Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem adding items to a listbox

Status
Not open for further replies.

philrosenberg

Technical User
Dec 3, 2003
15
GB
Hi all
This seems like it should be so easy yet I can't get it to work. I'm using microsoft visual c++ to create a dialog based application.
I've created one dialog box resource with a listbox in. Then added a CListBox object associated with it called m_list.
All I want to do is when the dialog opens have a list of various strings in the box so I'm doing something like.

CString String1 = "First list item"
CDlgList MyListDialog;
MyListDialog.m_list.AddString(string1);

however I'm getting a "debug assertion failed" error. Any ideas why, any help much appreciated.
 
I would guess that m_hWnd is null. Use the class wizard and associate the control with a variable name (member variables).

Matt
 
My bad... the m_hWnd = null would still be true but you should add the itmes in the "OnInitDialog" portion.

Matt
 
thanks zyrenthian. I can use AddString in the OnInitDialog function so I'll pass the strings to member variable strings and then add them to the listbox when OnInitDialog is called.

As an additional point I get the same error during runtime if I try to use addString in the dialog box constructor. If anyone knows and has the time to explain I'd be curious to know why it doesn't work in the constructor and why I can't access the Clistbox object befor I call doModal like other member variables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top