Access listbox from view's class
-
How do I initialize the dialog's list box in the View's member function ? Actually, I want to display a record in the listbox in the view button down handler fucntion? When I try to do, my program aborts in the listbox.AddString(...) fucntion? What could be possible wrong?
-
How do I initialize the dialog's list box in the View's member function ? Actually, I want to display a record in the listbox in the view button down handler fucntion? When I try to do, my program aborts in the listbox.AddString(...) fucntion? What could be possible wrong?
Sounds like the listbox hasn't been created yet. If the listbox is within a dialog class, you shouldn't initialise it until you receive a WM_INITDIALOG message - the OnInitDialog() method is called. So, in this case you could pass the relevant information to the dialog constructor, and then in the OnInitDialog() method of the dialog class, initialise the listbox there. Dave
-
Sounds like the listbox hasn't been created yet. If the listbox is within a dialog class, you shouldn't initialise it until you receive a WM_INITDIALOG message - the OnInitDialog() method is called. So, in this case you could pass the relevant information to the dialog constructor, and then in the OnInitDialog() method of the dialog class, initialise the listbox there. Dave
-
Yes, u are correct. But I would like to initailize with the data I read from the database. I am reading the records in the View's member function, so how do i pass the values read to the listbox?
The same principle applies: Something like: void CMyView::DoSomething() { CMyDialog dlg( this ); for ( each value in database ) { CString strValue = GetValueFromDataBase(); dlg.AddValue( strValue ); } if ( IDOK == dlg.DoModal() ) { // Do something with it } else { // Panic / shoot user } } class CMyDialog : public CDialog { // All the usual stuff public: void AddValue(const CString& strValue); private: CStringList m_lstValues; }; void CMyDialog::AddValue(const CString& strValue) { m_lstValues.AddTail( strValue ); } BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); // Add the values for ( POSITION pos = m_lstValues.GetHeadPosition() ; pos != NULL ; ) m_lstCtrl.AddString( m_lstValues.GetNext( pos ) ); return TRUE; } Dave