CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 1999
    Posts
    4

    Help! SetActiveView problem

    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




  2. #2
    Join Date
    May 1999
    Posts
    14

    Re: Help! SetActiveView problem

    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.


  3. #3
    Join Date
    Apr 1999
    Posts
    4

    Re: Help! SetActiveView problem

    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);
    }





  4. #4
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Help! SetActiveView problem

    In your frame, you ahve to SAVE a pointer to the TreeView and to the ListView and then use them

    Sally


  5. #5
    Join Date
    May 1999
    Posts
    14

    Re: Help! SetActiveView problem

    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.


  6. #6
    Join Date
    Apr 1999
    Posts
    4

    Re: Help! SetActiveView problem

    Thanks for your quick response!

    It is working now. thanks again for your help.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured