当您单击左窗格树控件时,如何在右窗格的编辑框中显示数据 [英] How to display the data in edit box of right pane when u click on the left pane tree control
问题描述
我已经在MFC中创建了MDI应用程序,我已经完成了左右窗格的分割页面,并且我已经在左侧添加了树控件并在右窗格中编辑了控件。
我的问题是如何在你点击树控件时从INI文件中获取数据,并且数据应该显示在右窗格中。
我尝试过:
void CFormLeft :: OnInitialUpdate()
{
CFormView :: OnInitialUpdate();
HTREEITEM hParent = m_TreeCtrl.InsertItem(LSTUDENT DETAILS,TVI_ROOT);
HTREEITEM hChild = m_TreeCtrl.InsertItem(LSTUDETN1,hParent,TVI_LAST);
HTREEITEM hChild1 = m_TreeCtrl.InsertItem(LSTUDETN2,hParent,TVI_LAST);
HTREEITEM hChild2 = m_TreeCtrl.InsertItem(LSTUDETN3,hParent,TVI_LAST);
HTREEITEM hChild3 = m_TreeCtrl.InsertItem(LSTUDETN4,hParent,TVI_LAST);
HTREEITEM hChild4 = m_TreeCtrl.InsertItem(LSTUDETN5,hParent,TVI_LAST);
// HTREEITEM hItem = m_TreeCtrl.GetSelectedItem();
// CString strItemText = m_TreeCtrl.GetItemText(hItem);
}
无效CFormLeft :: OnSelchangedTree1(NMHDR * pNMHDR,LRESULT * pResult)
{
NM_TREEVIEW * pNMTreeView =(NM_TREEVIEW *)pNMHDR;
// TODO:在这里添加你的控制通知处理程序代码
HTREEITEM hItem = m_TreeCtrl.GetSelectedItem();
CString strItemText = m_TreeCtrl.GetItemText(hItem);
// MessageBox(strItemText);
//m_student1.SetWindowText(L\"DETAILS OF SURESH);
* pResult = 0;
您需要访问包含编辑控件的右侧窗格。怎么做取决于你的窗格是如何组织的。
我假设一个CSplitterWnd
包含两个静态窗格树控件和编辑控件。然后你有三个选择:
- 从父窗口创建时将信息传递给
CFormLeft
类
- 从父窗口获取运行时的信息
- 将相应的功能添加到父窗口
在所有情况下,父窗口(
CSplitterWnd
)窗口应该包含窗格的成员(CLeftPane
和CRightPane
)。
及其指针()作为父参数传递。
第一种情况是将CRightPane *
成员添加到以某种方式初始化的CLeftPane
类中(构造函数或setter函数) ;从父窗口调用)。
对于第二种情况,实现一个函数从分割器父窗口获取指向右窗格的指针,转换父窗口从内部CLeftPane
并调用getter函数
CMySplitterWnd * pParent =(CMySplitterWnd *)GetParent();
// 必须实施:
// CRightPane * CMySplitterWnd :: GetRightPane(){return m_pRightPane; }
CRightPane * pRightPane = pParent-> GetRightPane();
一旦有了指向右侧窗格视图的指针,就可以调用功能或根据需要发送消息。如有必要,可以为CRightPane *
类添加函数以执行特定任务(例如,用于访问编辑控件)。
对于第三种情况,在父级中实现一个将命令转发到右窗格的函数
CMySplitterWnd * pParent =(CMySplitterWnd *)GetParent();
// 必须实施:
// CMySplitterWnd :: SetRightPaneEditText(const CString& s)
// {
// m_pRightPane-> ; m_editCtrl.SetWindowText(strItem);
// }
pParent-> SetRightPaneEditText(strItemText );
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;
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 aCSplitterWnd
with two static panes containing a tree control and an edit control. Then you have three options:
- Passing the information to your
CFormLeft
class upon creation from the parent window
- Get the information during run-time from the parent window
- Add appropriate functions to the parent window
In all cases the parent (
CSplitterWnd
) window should have members for the panes (CLeftPane
andCRightPane
).
[EDIT]
and a pointer to it (this
) must be passed as parent parameter when creating the pane views.
[EDIT]
For the first case add aCRightPane*
member to yourCLeftPane
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 withinCLeftPane
and call the getter function
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 theCRightPane*
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
CMySplitterWnd *pParent = (CMySplitterWnd *)GetParent(); // Must be implemented: // CMySplitterWnd::SetRightPaneEditText(const CString& s) // { // m_pRightPane->m_editCtrl.SetWindowText(strItem); // } pParent->SetRightPaneEditText(strItemText);
这篇关于当您单击左窗格树控件时,如何在右窗格的编辑框中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!