954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Retrieve text from combobox (VC++)

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
}
CreativeCoding
Light Poster
40 posts since Mar 2010
Reputation Points: 33
Solved Threads: 1
 

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

TaSkOnE
Newbie Poster
9 posts since Mar 2010
Reputation Points: 10
Solved Threads: 1
 

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
jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

Thanks guys

CreativeCoding
Light Poster
40 posts since Mar 2010
Reputation Points: 33
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You