Problem getting value from combobox and late binding
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

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

--
Click here to reveal e-mail address

Reply to this message...
 
    
moondaddy
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.

--
Click here to reveal e-mail address
"moondaddy" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Jeffrey Tan (VIP)
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.

Reply to this message...
 
 
System.Object
System.Windows.Forms.ComboBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com