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
}

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!!!

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.