Home All Groups Group Topic Archive Search About

ComboBox HELP Pleasse!

Author
23 Feb 2006 3:55 AM
D
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)

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

In the click method, I check the value of

Combobox1.SelectedValue.ToString

It is returning "System.Data.DataRowView" as the value of the
item. What is wrong? Any idea?

Thank you in advance.

Author
23 Feb 2006 4:41 AM
Nathan Sokalski
You are missing the key component of code that involves databinding. You
must call the DataBind() method after setting the DataSource property. In
your case, it looks like you need the following line:

Combobox1.DataBind()

I think this will fix your problem, if not, let me know. Good Luck!
--
Nathan Sokalski
njsokal***@hotmail.com
http://www.nathansokalski.com/

Show quoteHide quote
"D" <D@discussions.microsoft.com> wrote in message
news:ECEA6448-3A70-4703-A7D5-AB286321B1D4@microsoft.com...
>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)
>
> Combobox1.datasource = dt
> Combobox1.displaymember = "Names"
> Combobox1.Valuemember = "Keys"
>
> In the click method, I check the value of
>
> Combobox1.SelectedValue.ToString
>
> It is returning "System.Data.DataRowView" as the value of the
> item. What is wrong? Any idea?
>
> Thank you in advance.
>
Author
23 Feb 2006 8:49 AM
Cor Ligthert [MVP]
Nathan,

The DataBind is typical a webform method. A webform does not have a combobox
luckily for that they have named that a little bit the same control
DropDownList.

I hope this helps,

Cor
Author
23 Feb 2006 8:48 AM
Cor Ligthert [MVP]
D,

In what *event* are you using to get that selectedvalue.

Cor
Author
23 Feb 2006 1:55 PM
Kerry Moorman
D,

I copied and pasted your code into a VS 2003 Windows Form application. After
fixing 1 typo, your code worked for me. I changed this line:

     Combobox1.datasource = dt

to this line:

     ComboBox1.DataSource = dtAdjuster

Kerry Moorman


Show quoteHide quote
"D" 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)

> Combobox1.datasource = dt
> Combobox1.displaymember = "Names"
> Combobox1.Valuemember = "Keys"
>
> In the click method, I check the value of
>
> Combobox1.SelectedValue.ToString
>
> It is returning "System.Data.DataRowView" as the value of the
> item. What is wrong? Any idea?
>
> Thank you in advance.
>
Author
23 Feb 2006 3:54 PM
Cor Ligthert [MVP]
Kerry,

It was some sample code I made, I did not see this one change.
(I don't see the reason, this is the only change I use forever dt)

Good catch,

:-)

Cor

Show quoteHide quote
"Kerry Moorman" <KerryMoor***@discussions.microsoft.com> schreef in bericht
news:B050E395-B0F9-4FB4-ADD7-4B11EE609DCD@microsoft.com...
> D,
>
> I copied and pasted your code into a VS 2003 Windows Form application.
> After
> fixing 1 typo, your code worked for me. I changed this line:
>
>     Combobox1.datasource = dt
>
> to this line:
>
>     ComboBox1.DataSource = dtAdjuster
>
> Kerry Moorman
>
>
> "D" 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)
>>
>> Combobox1.datasource = dt
>> Combobox1.displaymember = "Names"
>> Combobox1.Valuemember = "Keys"
>>
>> In the click method, I check the value of
>>
>> Combobox1.SelectedValue.ToString
>>
>> It is returning "System.Data.DataRowView" as the value of the
>> item. What is wrong? Any idea?
>>
>> Thank you in advance.
>>