C# Combobox Selection
I am populating a combobox dropdown with node fields from an Xml document. I have that working. Now I have the text in the dropdown menu of the combobox. I want to be able to press a 'Go' button and use the selected text. What are the comman开发者_StackOverflowds please?
Have a look at the SelectedText property of ComboBox. It will return a string containing the currently selected text (ie. the text of the currently selected item) of the combo box.
To handle this from a button press, add an OnClick event handler to the button, and in this event handler get the SelectedText and do what you need with it.
During events, cboMyCombo.SelectedText
may be null because its value has been cleared: "For example, if you retrieve the SelectedText value in a button Click event handler, the value will be an empty string." read here.
You may just want to try using cboMyCombo.Text
精彩评论