Click to See Complete Forum and Search --> : Help! SetActiveView problem
allisons
May 10th, 1999, 02:56 PM
I am using the explorer type interface with a treeview on the left and listview on the right side. I added right click context menu support for my treeview. When I right click treeview item, I need to do something in my listview. The problem is while the focus is on the treeview I can't seem to make some normal function call work. for example, GetListCtrl()->GetItemCount always returns 0 value.
I was trying to fix this problem by setting listview as the active view:
////////////////////////////////////////////////////////////////////////////////////////////////
CMyListView* pChildView;
GetParentFrame()->SetActiveView(pChildView, TRUE); // assertion failed error right here!!!
GetListCtrl()->GetItemCount( );
////////////////////////////////////////////////////////////////////////////////////////////
So what should I do to set focus to my listview?
Thanks,
Coco
Alan Benett
May 10th, 1999, 03:10 PM
Hi there!
It seems you have passed an uninitialized pointer to the SetActiveView-function.
That might have caused the assertion failure.
CMyView* pView; // this only declares a pointer to a CMyView-class
// however it doesn't yet point to your view!!
GetActiveFrame()->SetActiveView (pView, ...);
The cure might be to initialize the pointer with a GetActiveView() (or similar) function.
Depends on from where you want to get a pointer to your view.
I.e.
CMyView* pView = (CMyView*) GetActiveView();
Hope this helps.
Best regards.
Alan.
allisons
May 10th, 1999, 03:53 PM
Thank you. Like you suggested, I made some changes, no assertion error but...
CMyListView* pView = (CMyListView*)GetParentFrame()-> GetActiveView();
// pView points to treeview??
GetParentFrame()->SetActiveView(pView, TRUE); // assertion failed right here before
CMyListView is a class derived from CListView. If using GetActiveView(), I can only get a pointer points to my treeview which has the current focus (this's not what I what to do).
How can I set my list view as the active view? Hope I am not confusing you more.
Call stack traces error back to:
************************************
void CFrameWnd::SetActiveView(CView* pViewNew, BOOL bNotify)
{
#ifdef _DEBUG
if (pViewNew != NULL)
{
ASSERT(IsChild(pViewNew)); // failed here!
ASSERT_KINDOF(CView, pViewNew);
}
sally
May 10th, 1999, 08:21 PM
In your frame, you ahve to SAVE a pointer to the TreeView and to the ListView and then use them
Sally
Sally
May 10th, 1999, 08:21 PM
In your frame, you ahve to SAVE a pointer to the TreeView and to the ListView and then use them
Sally
Alan Benett
May 11th, 1999, 02:07 PM
Hi there again!
Well, I'm not quite sure from where you want to set your CMyListView as active view.
I.e. from within your Document-class or from within your Mainframe-class...?
And have you created your views ("explorerlike" you said, right?!) in a splitter-wnd?
If you have set up your views within a splitter-window, you usually create them in the
OnCreateClient-function of your CChildFrame-Class (MDI) or something like that.
Further, you should have created a CSplitterWnd as a member of the CChildFrame-Class. (let's assume you called it m_SplitWnd).
Then you could get a pointer to your CMyListView like this:
CMyListView* pView = (CMyListView*) m_SplitWnd.GetPane ( /* row, column */ );
Well, it gets more complicated if you have not set up a splitter window.
However, you could iterate through the views that are attached to your document
(from within your document) using the GetFirstView(), and GetNextView()-Functions.
Hope this helps.
Regards.
Alan.
allisons
May 12th, 1999, 08:30 AM
Thanks for your quick response!
It is working now. thanks again for your help.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.