Re: How to Manipulate Fields (text box) in CFormView
rajeevanuk@googlemail.com wrote:
Hello all,
Thanks for the Reply...
I've tried Using OnInitialUpdate() and executing the following code:
txtName.SetWindowTextA("Hello");
Which word without any problem when I do it in a Button Click or so...
But when i Tried in OnInitUpdate() it throws an Error:
"Debug Assertion Failed!"
Let me give you How I'm loading this FormView..
I have One Common Document, MainFrame, ChildFrame. I use the following
Code to add and Load
--
pDocTemplateSearchForm = new CMultiDocTemplate(IDR_NavelCoreTYPE,
RUNTIME_CLASS(CNavelCoreDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(frmSearch));
if (!pDocTemplateSearchForm)
return FALSE;
AddDocTemplate(pDocTemplateSearchForm);
---
On Menu Selected:
((CDocTemplate*) pDocTemplateSearchForm)-> pDocTemplateSearchForm
(NULL);
As Ajay mentioned, OnInitialUpdate() may get called more than once, and the
first time the controls may not yet be created. Try like this
if (::IsWindow(txtName.GetSafeHwnd())
{
txtName.SetWindowTextA("Hello");
}
This certainly can do no harm, because if te window does not exist then
SetWindowText() cannot succeed.
Is there some reason you are using SetWindowTextA() rather than SetWindowText()?
Normally, you would write
txtName.SetWindowText(_T("Hello"));
which will compile and run correctly in both MBCS and Unicode mode.
Or if you know you are only going to compile for Unicode
txtName.SetWindowText(L"Hello");
--
David Wilkinson
Visual C++ MVP