Click here to Skip to main content
15,885,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created the MDI app in MFC , I have done up to splitted page as left and right pane ,And I have added the tree control in left and edit control in right pane as well.

My problem is how to get the data from INI file the moment when u click on the tree control and the data should be displayed in right pane.

What I have tried:

void CFormLeft::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	HTREEITEM hParent = m_TreeCtrl.InsertItem(L"STUDENT DETAILS", TVI_ROOT);
	HTREEITEM hChild = m_TreeCtrl.InsertItem(L"STUDETN1", hParent, TVI_LAST);
	HTREEITEM hChild1 = m_TreeCtrl.InsertItem(L"STUDETN2", hParent, TVI_LAST);
	HTREEITEM hChild2 = m_TreeCtrl.InsertItem(L"STUDETN3", hParent, TVI_LAST);
	HTREEITEM hChild3 = m_TreeCtrl.InsertItem(L"STUDETN4", hParent, TVI_LAST);
	HTREEITEM hChild4 = m_TreeCtrl.InsertItem(L"STUDETN5", hParent, TVI_LAST);
	

	//HTREEITEM hItem = m_TreeCtrl.GetSelectedItem();

	//CString strItemText = m_TreeCtrl.GetItemText(hItem);
}

void CFormLeft::OnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

	// TODO: Add your control 	notification handler code here
	HTREEITEM hItem = m_TreeCtrl.GetSelectedItem();
	CString strItemText = m_TreeCtrl.GetItemText(hItem);

	//MessageBox(strItemText);
	//m_student1.SetWindowText(L"DETAILS OF SURESH");
	
	*pResult = 0;
Posted
Updated 7-Nov-17 3:44am
v3
Comments
Richard MacCutchan 7-Nov-17 9:39am    
The usual way is for the TreeView event handler to send a message to the other Window.

1 solution

You need access to the right pane that contains the edit control. How to do that depends on how your panes are organised.

I assume a CSplitterWnd with two static panes containing a tree control and an edit control. Then you have three options:

  1. Passing the information to your CFormLeft class upon creation from the parent window
  2. Get the information during run-time from the parent window
  3. Add appropriate functions to the parent window
In all cases the parent (CSplitterWnd) window should have members for the panes (CLeftPane and CRightPane).
[EDIT]
and a pointer to it (this) must be passed as parent parameter when creating the pane views.
[EDIT]

For the first case add a CRightPane* member to your CLeftPane class that is initialised in some way (constructor or a setter function; both called from the parent window).

For the second case implement a function to get a pointer to the right pane from the splitter parent window, cast the parent window from within CLeftPane and call the getter function
C++
CMySplitterWnd *pParent = (CMySplitterWnd *)GetParent();
// Must be implemented:
// CRightPane* CMySplitterWnd::GetRightPane() { return m_pRightPane; }
CRightPane* pRightPane = pParent->GetRightPane();

Once you have the pointer to the right pane view, you can call functions or send messages as required. If necessary add functions to the CRightPane* class for specific tasks (e.g. for accessing the edit control).

For the third case implement a function in the parent that forwards commands to the right pane
C++
CMySplitterWnd *pParent = (CMySplitterWnd *)GetParent();
// Must be implemented:
// CMySplitterWnd::SetRightPaneEditText(const CString& s)
// { 
// m_pRightPane->m_editCtrl.SetWindowText(strItem); 
// }
pParent->SetRightPaneEditText(strItemText);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900