Home All Groups Group Topic Archive Search About

How to assign value to a dropdown box items?

Author
7 Oct 2006 9:46 AM
Anil Gupte
I am trying to use a dataset to assign a display name (one column from a
table) and also associate a value (2nd column) to each item in a dropdown
combobox.  I tried it this way:

DropDownProfiles.DataSource = WizoProfilesDataSet
DropDownProfiles.ValueMember =
WizoProfilesDataSet.Tables("Profiles").Columns(0).ColumnName
DropDownProfiles.DisplayMember =
WizoProfilesDataSet.Tables("Profiles").Columns(1).ColumnName

And also this way
For RowIndex As Integer = 0 To
WizoProfilesDataSet.Tables("Profiles").Rows.Count - 1
   DropDownProfiles.Items.Add(WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(1))
   DropDownProfiles.ValueMember =
WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
Next

But both don't work.  What I really want to do is something like:
DropDownProfiles.items.item(rowindex).ValueMember =
WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
but there is no such member or property.

How does one do this?

Thanx,

Author
7 Oct 2006 2:03 PM
Kerry Moorman
Anil,

The first technique you show looks like it should work. What do you mean
when you say that it does not work?

Kerry Moorman


Show quoteHide quote
"Anil Gupte" wrote:

> I am trying to use a dataset to assign a display name (one column from a
> table) and also associate a value (2nd column) to each item in a dropdown
> combobox.  I tried it this way:
>
>  DropDownProfiles.DataSource = WizoProfilesDataSet
>  DropDownProfiles.ValueMember =
> WizoProfilesDataSet.Tables("Profiles").Columns(0).ColumnName
>  DropDownProfiles.DisplayMember =
> WizoProfilesDataSet.Tables("Profiles").Columns(1).ColumnName
>
> And also this way
> For RowIndex As Integer = 0 To
> WizoProfilesDataSet.Tables("Profiles").Rows.Count - 1
>    DropDownProfiles.Items.Add(WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(1))
>    DropDownProfiles.ValueMember =
> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
> Next
>
> But both don't work.  What I really want to do is something like:
> DropDownProfiles.items.item(rowindex).ValueMember =
> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
> but there is no such member or property.
>
> How does one do this?
>
> Thanx,
> --
> Anil Gupte
> www.keeninc.net
> www.icinema.com
>
>
>
Author
7 Oct 2006 5:01 PM
Anil Gupte
The control seeems to be frozen (shows a white area instead of the control)
and when I click it, it shows System.Data.DataViewManager....etc (the rest
is cut off) for the Display property instead of the database values like
"Kids", "Adults".

I tried it again because there seemed to be some confusion with the
ValueMember being a string not integer, and it is no longer frozen, but the
list is not populated with anything.

Thanx.
Show quoteHide quote
"Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message
news:CAFF38CC-1282-4514-94BF-97EE18D179E2@microsoft.com...
> Anil,
>
> The first technique you show looks like it should work. What do you mean
> when you say that it does not work?
>
> Kerry Moorman
>
>
> "Anil Gupte" wrote:
>
>> I am trying to use a dataset to assign a display name (one column from a
>> table) and also associate a value (2nd column) to each item in a dropdown
>> combobox.  I tried it this way:
>>
>>  DropDownProfiles.DataSource = WizoProfilesDataSet
>>  DropDownProfiles.ValueMember =
>> WizoProfilesDataSet.Tables("Profiles").Columns(0).ColumnName
>>  DropDownProfiles.DisplayMember =
>> WizoProfilesDataSet.Tables("Profiles").Columns(1).ColumnName
>>
>> And also this way
>> For RowIndex As Integer = 0 To
>> WizoProfilesDataSet.Tables("Profiles").Rows.Count - 1
>>
>> DropDownProfiles.Items.Add(WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(1))
>>    DropDownProfiles.ValueMember =
>> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
>> Next
>>
>> But both don't work.  What I really want to do is something like:
>> DropDownProfiles.items.item(rowindex).ValueMember =
>> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
>> but there is no such member or property.
>>
>> How does one do this?
>>
>> Thanx,
>> --
>> Anil Gupte
>> www.keeninc.net
>> www.icinema.com
>>
>>
>>
Author
7 Oct 2006 5:07 PM
Anil Gupte
Also, what I am really looking for here is
WizoProfilesDataSet.Tables("Profiles").Columns(0).ColumnValue not ColumnName
and of course there is no property called ColumnValue.

Show quoteHide quote
"Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message
news:CAFF38CC-1282-4514-94BF-97EE18D179E2@microsoft.com...
> Anil,
>
> The first technique you show looks like it should work. What do you mean
> when you say that it does not work?
>
> Kerry Moorman
>
>
> "Anil Gupte" wrote:
>
>> I am trying to use a dataset to assign a display name (one column from a
>> table) and also associate a value (2nd column) to each item in a dropdown
>> combobox.  I tried it this way:
>>
>>  DropDownProfiles.DataSource = WizoProfilesDataSet
>>  DropDownProfiles.ValueMember =
>> WizoProfilesDataSet.Tables("Profiles").Columns(0).ColumnName
>>  DropDownProfiles.DisplayMember =
>> WizoProfilesDataSet.Tables("Profiles").Columns(1).ColumnName
>>
>> And also this way
>> For RowIndex As Integer = 0 To
>> WizoProfilesDataSet.Tables("Profiles").Rows.Count - 1
>>
>> DropDownProfiles.Items.Add(WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(1))
>>    DropDownProfiles.ValueMember =
>> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
>> Next
>>
>> But both don't work.  What I really want to do is something like:
>> DropDownProfiles.items.item(rowindex).ValueMember =
>> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
>> but there is no such member or property.
>>
>> How does one do this?
>>
>> Thanx,
>> --
>> Anil Gupte
>> www.keeninc.net
>> www.icinema.com
>>
>>
>>
Author
7 Oct 2006 9:25 PM
Kerry Moorman
Anil,

No, the named column will be used to provide values to the combobox's
ValueMember property. Which I believe is what you want.

But I still don't understand why your code is not populating the combobox. I
tried similar code and it worked fine for me. Perhaps you should create a
small test project that just assigns DisplayMember and ValueMember to a
combobox and see if you can narrow down the problem.

Kerry Moorman


Show quoteHide quote
"Anil Gupte" wrote:

> Also, what I am really looking for here is
> WizoProfilesDataSet.Tables("Profiles").Columns(0).ColumnValue not ColumnName
> and of course there is no property called ColumnValue.
>
> --
> Anil Gupte
> www.keeninc.net
> www.icinema.com
>
> "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message
> news:CAFF38CC-1282-4514-94BF-97EE18D179E2@microsoft.com...
> > Anil,
> >
> > The first technique you show looks like it should work. What do you mean
> > when you say that it does not work?
> >
> > Kerry Moorman
> >
> >
> > "Anil Gupte" wrote:
> >
> >> I am trying to use a dataset to assign a display name (one column from a
> >> table) and also associate a value (2nd column) to each item in a dropdown
> >> combobox.  I tried it this way:
> >>
> >>  DropDownProfiles.DataSource = WizoProfilesDataSet
> >>  DropDownProfiles.ValueMember =
> >> WizoProfilesDataSet.Tables("Profiles").Columns(0).ColumnName
> >>  DropDownProfiles.DisplayMember =
> >> WizoProfilesDataSet.Tables("Profiles").Columns(1).ColumnName
> >>
> >> And also this way
> >> For RowIndex As Integer = 0 To
> >> WizoProfilesDataSet.Tables("Profiles").Rows.Count - 1
> >>
> >> DropDownProfiles.Items.Add(WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(1))
> >>    DropDownProfiles.ValueMember =
> >> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
> >> Next
> >>
> >> But both don't work.  What I really want to do is something like:
> >> DropDownProfiles.items.item(rowindex).ValueMember =
> >> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
> >> but there is no such member or property.
> >>
> >> How does one do this?
> >>
> >> Thanx,
> >> --
> >> Anil Gupte
> >> www.keeninc.net
> >> www.icinema.com
> >>
> >>
> >>
>
>
>
Author
8 Oct 2006 5:08 AM
Anil Gupte
OK!  Solved it!  I had two things wrong with it.  First, I had some stuff
left over under DataBindings that I had manully added using the properties
window and that was no doubt conflicting with it.  Secondly, I made a change
from:
DropDownProfiles.DataSource = WizoProfilesDataSet

to

DropDownProfiles.DataSource = WizoProfilesDataSet.Tables("Profiles")

and now it works - thanx for your help.
Show quoteHide quote
"Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message
news:8320420F-EF17-49CE-86F5-4A09FA41493F@microsoft.com...
> Anil,
>
> No, the named column will be used to provide values to the combobox's
> ValueMember property. Which I believe is what you want.
>
> But I still don't understand why your code is not populating the combobox.
> I
> tried similar code and it worked fine for me. Perhaps you should create a
> small test project that just assigns DisplayMember and ValueMember to a
> combobox and see if you can narrow down the problem.
>
> Kerry Moorman
>
>
> "Anil Gupte" wrote:
>
>> Also, what I am really looking for here is
>> WizoProfilesDataSet.Tables("Profiles").Columns(0).ColumnValue not
>> ColumnName
>> and of course there is no property called ColumnValue.
>>
>> --
>> Anil Gupte
>> www.keeninc.net
>> www.icinema.com
>>
>> "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message
>> news:CAFF38CC-1282-4514-94BF-97EE18D179E2@microsoft.com...
>> > Anil,
>> >
>> > The first technique you show looks like it should work. What do you
>> > mean
>> > when you say that it does not work?
>> >
>> > Kerry Moorman
>> >
>> >
>> > "Anil Gupte" wrote:
>> >
>> >> I am trying to use a dataset to assign a display name (one column from
>> >> a
>> >> table) and also associate a value (2nd column) to each item in a
>> >> dropdown
>> >> combobox.  I tried it this way:
>> >>
>> >>  DropDownProfiles.DataSource = WizoProfilesDataSet
>> >>  DropDownProfiles.ValueMember =
>> >> WizoProfilesDataSet.Tables("Profiles").Columns(0).ColumnName
>> >>  DropDownProfiles.DisplayMember =
>> >> WizoProfilesDataSet.Tables("Profiles").Columns(1).ColumnName
>> >>
>> >> And also this way
>> >> For RowIndex As Integer = 0 To
>> >> WizoProfilesDataSet.Tables("Profiles").Rows.Count - 1
>> >>
>> >> DropDownProfiles.Items.Add(WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(1))
>> >>    DropDownProfiles.ValueMember =
>> >> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
>> >> Next
>> >>
>> >> But both don't work.  What I really want to do is something like:
>> >> DropDownProfiles.items.item(rowindex).ValueMember =
>> >> WizoProfilesDataSet.Tables("Profiles").Rows(RowIndex).Item(0)
>> >> but there is no such member or property.
>> >>
>> >> How does one do this?
>> >>
>> >> Thanx,
>> >> --
>> >> Anil Gupte
>> >> www.keeninc.net
>> >> www.icinema.com
>> >>
>> >>
>> >>
>>
>>
>>