Unable to display List Box
Help, please....
I am a newbie in C++. In an MFC dialog, I put an Edit control and a List box. I want to populate the List box (m_List) with strings derived from the Edit box string.
- in the dialog's OnInitDialog, I tried to put
GetDlgItemText (..) // get text from Edit box
process the string //
m_List.AddString (..) // etc. several strings
m_List.SetCurSel (..) //
but GetDlgItemText could not work from OnInitDialog.
- When I put the above code in OnOK, the ListBox is populated for a fraction of seconds and soon disappear.
I have read the MSDN library, and tried other events (OnKillFocus, etc.) but could not get the dialog to stop to display the strings in the List Box. What should I do ? ...
Re: Unable to display List Box
I suspect your problem might be here...
Quote:
Originally posted by nugroho2
- When I put the above code in OnOK, the ListBox is populated for a fraction of seconds and soon disappear.
By default, OnOK and OnCancel will close the dialog box. Is that what happened to you?
If so, simple comment out the call to CDialog::OnOk()
Re: Unable to display List Box
Quote:
Originally posted by nugroho2
Help, please....
I am a newbie in C++. In an MFC dialog, I put an Edit control and a List box. I want to populate the List box (m_List) with strings derived from the Edit box string.
- in the dialog's OnInitDialog, I tried to put
GetDlgItemText (..) // get text from Edit box
process the string //
m_List.AddString (..) // etc. several strings
m_List.SetCurSel (..) //
but GetDlgItemText could not work from OnInitDialog.
- When I put the above code in OnOK, the ListBox is populated for a fraction of seconds and soon disappear.
I have read the MSDN library, and tried other events (OnKillFocus, etc.) but could not get the dialog to stop to display the strings in the List Box. What should I do ? ...
Okay, let's stop to catch our breath here. You want to put strings in the list based on what's in an edit control. Nobody has had a chance to put anything in the edit control at that point (as John said) so there is nothing to be gained by putting it there.
OnOK's default behavior is to close the dialog, so that probably isn't the place either, as the dialog will close if you call the base class implementation. What action taken by the user would indicate that it's time to populate the list box? Somebody else suggested a button, which is probably a good idea.