Problem getting value from combobox and late binding

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

using vb.net 1.1 I have a combobox which I'm trying to get the selected
item's value. the problem is that this class uses Option Explicit On and
Option Strict On so the following line gets a compile error:

m_GoToID = CType(cmbGoTo.SelectedItem.row(0), Int32)

with the blue squiggly under cmbGoTo.SelectedItem.row(0)

and the compile error is:

Option Strict On disallows late binding

I populated the combo by binding it to a dataset table.

Can anyone help on this?

Thanks
 
I figured it out. Earlier I had tried this:

objB.myCombo = CType(myCombo.SelectedValue, Int32)

but got an error (I forget just what the error was), but I've figured out
how to make this line work. In order to use 'SelectedValue', I needed to
first define the value member. So when I load data into the combo, I call
this line:

Me.myCombo.ValueMember = "ID"

Where ID is the name if the ID column in the dataset.

Now it works and compiles too when using Option Strict On.
 
Hi moondaddy,

I am glad you figure it out.

ComboBox.SelectedItem will return a System.Object type object, it did not
has a row(0) member, so you can not do like this.

Also, if you do not specify ValueMember for ComboBox, combobox.selectedvalue
will return null object.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top