Click here to Skip to main content
Licence 
First Posted 20 Jun 2003
Views 93,157
Bookmarked 24 times

Easy way to access listview from treeview and vice versa

By | 20 Jun 2003 | Article
Easy way to access listview from treeview and vice versa in a Windows Explorer style application.

Introduction

Sample screenshot

This is an easy way to access the listview from treeview and vice-versa in a Windows Explorer Style MFC application. (It is specified in step number 5 of 6 in the MFC app wizard)

Let's say the project name is "F".

What is to be done ?

  • Create an SDI application with Windows Explorer style, with name "F".
  • Add a public member variable (a pointer to CTreeView type) to CLeftView class with name m_treeview. This will be of the shape CTreeView * m_treeview.
  • Add a public member variable (a pointer to CListView type) to CFView class (where F is the name of the app.) with name m_listview. This will be of the shape CListView * m_listview.
  • Add a public member function and which is void with name GetViews() to the CMainFrame class
  • Write the following code in the function:
    void CMainFrame::GetViews()
    {
    //Code beginning
     //get the right view (the list view)
     CWnd* pWnd = m_wndSplitter.GetPane(0, 1);
     //cast the right view to the CFView type where F is 
     //the name of Application and store it in list variable
     CFView* list= DYNAMIC_DOWNCAST(CFView, pWnd);
     //get the left view (the tree view)
     pWnd = m_wndSplitter.GetPane(0, 0);
     //cast it to CLeftView type and store it in tree variable
     CLeftView * tree = DYNAMIC_DOWNCAST(CLeftView, pWnd);
     //store the list view in the m_listview variable 
     //(member of CLeftView class)
     tree->m_listview=list;
     //store the tree view in the m_treeview 
     //variable (member of CFView class)
     list->m_treeview=tree;
     //end of code
    }
  • Add GetViews(); in the CMainFrame::OnCreate() function just before "return true;"

So how do I use that code

To access the ListView from Treeview,

  • On any event you want (click, double click, select) in the CLeftView class, add the following code:
    m_listview->GetListCtrl().InsertColumn(0,"Test");

To access the TreeView From ListView,

  • On any event you want (click ,double click, select) in the CFView class, add the following code:
    m_treeview->GetTreeCtrl().InsertItem("Test");

I hope that I helped.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

kariem2k

Web Developer

Egypt Egypt

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGood One PinmemberMohammad A Gdeisat8:51 25 Jan '05  
Generalerror in code corrected Pinmemberdrake282:56 13 Nov '04  
GeneralNice article PinmemberBaldwinMartin17:26 5 Nov '04  
GeneralRe: Nice article Pinmemberdrake2810:36 11 Nov '04  
GeneralHelpful Pinmembereedwards11:41 11 Aug '03  
GeneralChild learning?! PinmemberLars [Large] Werner22:16 21 Jun '03  
GeneralRe: Child learning?! PinmemberOha Ooh10:23 24 Jun '03  
GeneralRe: Child learning?! PinmemberLars [Large] Werner10:37 24 Jun '03  
GeneralRe: Child learning?! PinmemberBaldwinMartin17:14 17 Nov '04  
GeneralRe: Child learning?! PinmemberLars [Large] Werner19:12 17 Nov '04  
GeneralRe: Child learning?! PinmemberBaldwinMartin19:58 17 Nov '04  
GeneralRe: Child learning?! PinmemberBaldwinMartin17:00 20 Nov '04  
GeneralThis is the worst article I have seen on CP PinmemberWangYun18:48 21 Jun '03  
GeneralRe: This is the worst article I have seen on CP PinmemberJohn M. Drescher21:17 21 Jun '03  
GeneralRe: This is the worst article I have seen on CP PinmemberGreg Ennis17:17 22 Jun '03  
GeneralRe: This is the worst article I have seen on CP PinmemberGernot Frisch20:42 3 Sep '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 21 Jun 2003
Article Copyright 2003 by kariem2k
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid