Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


MFC Question regarding Comboboxes

This topic is 5927 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. quick question that has me tearing my hair out (Which means that the answer is probably obvious !) I have a dialogue box which contains a combo box. I am trying to load the combobox data from my code as below, but It fails on the assertion. Any ideas / Suggestions ?

void CMyDlg::LoadClassList()

	CString strTemp1;
	CString strTemp2;
	CString strTemp3;
	CString strTemp4;

	//Set Up the Combo Box For Drawing

	// Delete all the items from the combo box.

	ASSERT(m_ClassList.GetCount() == 0);

	//Loop through all Classes in the Class System and Add them to the Combo Box in

	//The order they are stored in the Class List (so get Common Index)

	m_ClassList.AddString( strTemp1 );
	m_ClassList.AddString( strTemp2 );
	m_ClassList.AddString( strTemp3 );
	m_ClassList.AddString( strTemp4 );


Thanks, Bp.

Share this post

Link to post
Share on other sites


int GetCount( ) const;

Return Value

The number of items. The returned count is one greater than the index value of the last item (the index is zero-based). It is CB_ERR if an error occurs.


Call this member function to retrieve the number of items in the list-box portion of a combo box.

I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm

Share this post

Link to post
Share on other sites
Where are calling your LoadClassList()?

you should call it at WM_INITDIALOG and not at Create
Cos at the time, the comobobox has not been created yet.

Correct me if i''m wrong.

Share this post

Link to post
Share on other sites
At the moment I am calling that function at the bottom of the constructor for the Dialog box.

I''ll move it to be called on the message and see what happens.

Share this post

Link to post
Share on other sites
I have solved the first problem (I was calling the code from the dlg constructor. By calling it from teh combobox initialisation message I can be sure that the combobox has been created.

My new problem is the adding of data to the box. If I hard code it from teh dialog resource editor I can''t get the drop down section of the list to display, but if I click in the box and push the down key I can scroll through the box. But I can''t add the data to the box using the AddString() method. I think my problem is more fundamental, either I have not configured the box correctly or I misunderstand how to use it.

I would not have thought that I would need to display the drop down list, but that it would have happened automatically ?

If I use the AddString() or InsertString() methods I get an assert error again, but according to my documentation I don''t need to allocate memory before pushing data to the combobox.

Hope this helps you help me !


p.s. Just read Invader X Post again. Thanks for telling me what I already knew, I guess that either you just wanted to post or you didn''t read my question.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!