Communication between TreeView and FormView
-
In my SDI application, I have two views, Treeview and FormView. I placed Edit control on FormView. I have to change value of Edit control by clicking on Tree. Both are different classes. But I am unable to access FormView Class members from Treeview. How can I do that?
void CLeftView::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
//some code
CRightView *rView = new CRightView();
if(rView!=NULL)
{
rView->m_Edit1.SetWindowText(_T("ok"));
}
}Code gives Debug Assertion Error.
-
In my SDI application, I have two views, Treeview and FormView. I placed Edit control on FormView. I have to change value of Edit control by clicking on Tree. Both are different classes. But I am unable to access FormView Class members from Treeview. How can I do that?
void CLeftView::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
//some code
CRightView *rView = new CRightView();
if(rView!=NULL)
{
rView->m_Edit1.SetWindowText(_T("ok"));
}
}Code gives Debug Assertion Error.
Will
CDocument::UpdateAllViews
will help you ? http://msdn.microsoft.com/en-us/library/eys41xfw(VS.80).aspx[^] Also look at the example given below, http://msdn.microsoft.com/en-us/library/ysfkkk2h(VS.80).aspx[^] Regards, Paresh. -
In my SDI application, I have two views, Treeview and FormView. I placed Edit control on FormView. I have to change value of Edit control by clicking on Tree. Both are different classes. But I am unable to access FormView Class members from Treeview. How can I do that?
void CLeftView::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
//some code
CRightView *rView = new CRightView();
if(rView!=NULL)
{
rView->m_Edit1.SetWindowText(_T("ok"));
}
}Code gives Debug Assertion Error.
You are creating new View object CRightView *rView = new CRightView();.Instead of this you should get the the attached View object.
-@SuDhIrKuMaR@-
-
You are creating new View object CRightView *rView = new CRightView();.Instead of this you should get the the attached View object.
-@SuDhIrKuMaR@-
Sir, I am very confused. Please give me some example. How do I create attached view object?
-
Sir, I am very confused. Please give me some example. How do I create attached view object?
Try to run this code. CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd); CView* pFrmView = pFrame->GetActiveView (); CRightView *rView = NULL; if (pFrmView->IsKindOf (RUNTIME_CLASS (CRightView))) rView = (CRightView *)pFrmView; (Your Doc Class Name) * pDoc = GetDocument() if(rView == NULL) { POSITION pos = pDoc->GetFirstViewPosition(); while (pos) { CView* pView = GetNextView (pos); if (pView->IsKindOf (RUNTIME_CLASS (CFormView))) { rView = (CRightView *)pFrmView; } } } if(rView!=NULL) { rView->m_Edit1.SetWindowText(_T("ok")); }
-@SuDhIrKuMaR@-
-
Try to run this code. CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd); CView* pFrmView = pFrame->GetActiveView (); CRightView *rView = NULL; if (pFrmView->IsKindOf (RUNTIME_CLASS (CRightView))) rView = (CRightView *)pFrmView; (Your Doc Class Name) * pDoc = GetDocument() if(rView == NULL) { POSITION pos = pDoc->GetFirstViewPosition(); while (pos) { CView* pView = GetNextView (pos); if (pView->IsKindOf (RUNTIME_CLASS (CFormView))) { rView = (CRightView *)pFrmView; } } } if(rView!=NULL) { rView->m_Edit1.SetWindowText(_T("ok")); }
-@SuDhIrKuMaR@-
Now, i get this error: Unhandled exception at 0x00530a33 in MyPrg.exe: 0xC0000005: Access violation reading location 0x1271e40a. and control goes to:
void CWnd::SetWindowText(LPCTSTR lpszString)
{
ENSURE(this);
ENSURE(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));if (m\_pCtrlSite == NULL) ::SetWindowText(m\_hWnd, lpszString); else **m\_pCtrlSite->SetWindowText(lpszString);// control points here**
}