Introduction
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()
{
CWnd* pWnd = m_wndSplitter.GetPane(0, 1);
CFView* list= DYNAMIC_DOWNCAST(CFView, pWnd);
pWnd = m_wndSplitter.GetPane(0, 0);
CLeftView * tree = DYNAMIC_DOWNCAST(CLeftView, pWnd);
tree->m_listview=list;
list->m_treeview=tree;
}
- Add
GetViews();
in the CMainFrame::OnCreate()
function just before "return true;
"
So how do I use that code
To access the ListView from Treeview,
To access the TreeView From ListView,
I hope that I helped.