Home All Groups Group Topic Archive Search About

How to query the key and value pair in ComboBox

Author
22 Feb 2006 8:09 PM
Dursun
I am using the following code as an example. Once the user selects an item
from the combobox (e.g., "Martin"), how can I access the value of that item
(e.g., "1")?

Thank you,

DD

Dim dtAdjuster as new DataTable
dtAdjuster.Columns.add("Names")
dtAdjuster.Columns.add("Keys")

dtAdjuster.loaddatarow(new object() {"Martin", "1"},true)
dtAdjuster.loaddatarow(new object() {"Cor","2"},true)

'This can all in probably hundred other ways, this is the way I do it.

Combobox1.datasource = dt
Combobox1.displaymember = "Names"
Combobox1.Valuemember = "Keys"

Author
22 Feb 2006 8:37 PM
Jim Wooley
Show quote Hide quote
> I am using the following code as an example. Once the user selects an
> item from the combobox (e.g., "Martin"), how can I access the value of
> that item (e.g., "1")?
>
> Dim dtAdjuster as new DataTable
> dtAdjuster.Columns.add("Names")
> dtAdjuster.Columns.add("Keys")
> dtAdjuster.loaddatarow(new object() {"Martin", "1"},true)
> dtAdjuster.loaddatarow(new object() {"Cor","2"},true)
>
> 'This can all in probably hundred other ways, this is the way I do it.
>
> Combobox1.datasource = dt
> Combobox1.displaymember = "Names"
> Combobox1.Valuemember = "Keys"

Combobox1.SelectedValue.ToString
Author
22 Feb 2006 9:05 PM
Dursun
I tried that, it is returning "System.Data.DataRowView" as the value of the
item. What is wrong? Any idea?



Show quoteHide quote
"Jim Wooley" wrote:

> > I am using the following code as an example. Once the user selects an
> > item from the combobox (e.g., "Martin"), how can I access the value of
> > that item (e.g., "1")?
> >
> > Dim dtAdjuster as new DataTable
> > dtAdjuster.Columns.add("Names")
> > dtAdjuster.Columns.add("Keys")
> > dtAdjuster.loaddatarow(new object() {"Martin", "1"},true)
> > dtAdjuster.loaddatarow(new object() {"Cor","2"},true)
> >
> > 'This can all in probably hundred other ways, this is the way I do it.
> >
> > Combobox1.datasource = dt
> > Combobox1.displaymember = "Names"
> > Combobox1.Valuemember = "Keys"
>
> Combobox1.SelectedValue.ToString
>
>
>