Home All Groups Group Topic Archive Search About

Getting the text from a bound combobox.

Author
30 Jun 2006 8:39 PM
reidarT
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

Author
29 Jun 2006 9:06 PM
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

Show quoteHide quote
> 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
>
Author
30 Jun 2006 5:00 AM
Cor Ligthert [MVP]
Reidar,

Why not simple?

str = cboName.text

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

Cor

Show quoteHide quote
"reidarT" <rei***@eivon.no> schreef in bericht
news:ew%23a2w7mGHA.3588@TK2MSFTNGP04.phx.gbl...
>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
>
Author
30 Jun 2006 9:03 PM
reidarT
I found the answer myself. Just use me.cboName.Text
reidarT
Show quoteHide quote
"reidarT" <rei***@eivon.no> skrev i melding
news:ew%23a2w7mGHA.3588@TK2MSFTNGP04.phx.gbl...
>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
>
Author
30 Jun 2006 5:01 AM
Cor Ligthert [MVP]
Sorry,

I had not seen your reply before sending my message

Cor

Show quoteHide quote
"reidarT" <rei***@eivon.no> schreef in bericht
news:O6jWR%237mGHA.4960@TK2MSFTNGP04.phx.gbl...
>I found the answer myself. Just use me.cboName.Text
> reidarT
> "reidarT" <rei***@eivon.no> skrev i melding
> news:ew%23a2w7mGHA.3588@TK2MSFTNGP04.phx.gbl...
>>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
>>
>
>