0

So I have looked and looked and wasn't able to find how to retrieve text from a selected option in a combobox. I have just started visual c++ so I don't really understand a lot. But I used to work with Visual C# before.

So, is there any way?

if(comboboxslectedvaluethingy == "option 2"){
//Do something
}

Edited by CreativeCoding: n/a

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by CreativeCoding
0

Hi CreativeCoding,

what you are lookin for is the function GetCurSel() which returns the index of the currently selected cbo item.

eg:

if(m_cbo1.GetCurSel() == 0)
	{
		//do something
	}

IMPORTANT: m_cbo1 needs to be a control of type CComboBox and not a CString!!!

0

He didn't specify, but from another post I believe he is doing a CLR winforms and not an MFC application.

It would be:

comboBox1->SelectedItem  //The selected item (of type "object")
                                          //must be casted before using
comboBox1->SelectedIndex //The (0 based) index of the item
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.