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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CComboBox::GetCurSel()

Status
Not open for further replies.

kaya17

Programmer
Feb 9, 2004
78
SG
hi, all,
i have a class called CComboData, this class is to open a .txt file and retrieves the wordlist and store them in CStringArray variable, m_stringarray.
then, the combo box retrieves the strings stored in m_stringarray and display them,
say in the wordlist.txt file, the contents are:
hello
hi
how
good
thank


so the combo box displays:
hello
how
good
thank

there is a method called GetString in the CComboData class,
it is something like this:

CString CComboData::GetString(int i)
{
return m_stringarray.GetAt(i);}

in my dialog class,
i need to get what user selects, so i made my code like this:

dlg.m_combo_data.GetString(dlg.m_combo_box.GetCurSel());

m_combo_data is of type CComboData, and m_combo_box is of the type CComboBox.

but when i ran it, it gave an assert error:
saying ASSERT:):IsWindow(m_hWnd)); in the _AFXWIN_INLINE int CComboBox::GetCurSel() const function.

anyone can tell me what's wrong here?

THANKS A LOT!

kaya
 
Where are you calling GetCurSel? When you assert, follow the call stack backwards and see what is causing the assert. If it is in a function that executes before the window has time to load, you will see this error. You may need to put a if(m_hWnd) in the function to make it work correctly or change when it executes.

Matt
 
You can't do a call like that if your DoModal has exited.

What you should do is copy the selected string into a in the dialog's OnOK CString member of the dialog. You can safely access that member when the dialog has closed.

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Yeah, i copy the string to a cstring variable before closing the dialog, then it works.

Thanks so much!

kaya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top