Getting the text from a bound combobox.

  • Thread starter Thread starter Jim Wooley
  • Start date Start date
J

Jim Wooley

The behavior for SelectedText will vary depending on how you are populating
the box. You say the method doesn't work. What is it returning?

Be aware that if no value is selected in the combo box, SelectedText (as
well as SelectedValue) will be Nothing. Calling .ToString on Nothing may
result in an exception. Also, If you set the ValueMember of the ComboBox,
you can check the SelectedValue with the same potential for null exception
handling. Additionally, if you are binding an object with a property of type
string to SelectedText or SelectedValue, make sure to check for Nothing before
doing any processing on the value.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 
Reidar,

Why not simple?

str = cboName.text

(your code is more listbox style with a combobox is the selectedtext in the
textbox)

Cor
 
I want to get the text from a bound combobox in a variable
I try to use strVar = me.cboName.SelectedText.Tostring, but it doesn't work.

reidarT
 
Back
Top