Click to See Complete Forum and Search --> : Displaying a database record in CEditView


TrimTrom
May 9th, 1999, 12:00 PM
VC++6.0, Windows 98

I am hoping someone can help me.

I have created an application with AppWizard, using document/view, and
have turned it into a splitter application with three panes, one of
which is a CEditView. In this editview I wish to display a text message
which is in a text field in a local Access database.

I have put the following code in the CEditView class constructor:

CPTEditView::CPTEditView()
{
CSplytRecordset MyRecordset;
MyRecordset.Open();
MyRecordset.MoveFirst();

CEdit &pEdit = GetEditCtrl();

pEdit.SetWindowText((LPCTSTR)MyRecordset.m_Subjectfld);
}




In the above I have opened a CDAORecordset, and accessed the first
record, and tried to display it in the editview with SetWindowText from
the underlying edit control. The program compiles OK, but when I run it
I get a debug error in the base CWnd::SetWindowText in the MFC file
Winocc.cpp:


void CWnd::SetWindowText(LPCTSTR lpszString)
{
ASSERT(::IsWindow(m_hWnd));

if (m_pCtrlSite == NULL)
::SetWindowText(m_hWnd, lpszString);
else
m_pCtrlSite->SetWindowText(lpszString);
}




The program fails on the assert.

What am I doing wrong? Should I not try and display the text in the
editview constructor? The program seems not to be able to find the edit
control underlying the editview.

All help would be appreciated, especially with code.

TrimTrom

----------------------------------
Paul Trimming
Email: paul.trimming@dial.pipex.com
4, High St, Merstham
Surrey RH1 3EA, England
----------------------------------

May 9th, 1999, 12:16 PM
Tried TexOut Function???

Kitai

May 9th, 1999, 12:29 PM
Place the call to SetWindowText later (ie: CPTEditView::OnInitialUpdate).