473,508 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to assign value to a dropdown box items?

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.Tab les("Profiles").Rows(RowIndex).Item(1))
DropDownProfiles.ValueMember =
WizoProfilesDataSet.Tables("Profiles").Rows(RowInd ex).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(RowInd ex).Item(0)
but there is no such member or property.

How does one do this?

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com
Oct 7 '06 #1
5 2084
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.Tab les("Profiles").Rows(RowIndex).Item(1))
DropDownProfiles.ValueMember =
WizoProfilesDataSet.Tables("Profiles").Rows(RowInd ex).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(RowInd ex).Item(0)
but there is no such member or property.

How does one do this?

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com
Oct 7 '06 #2
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.
--
Anil Gupte
www.keeninc.net
www.icinema.com

"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:CA**********************************@microsof t.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.Cou nt - 1

DropDownProfiles.Items.Add(WizoProfilesDataSet.Ta bles("Profiles").Rows(RowIndex).Item(1))
DropDownProfiles.ValueMember =
WizoProfilesDataSet.Tables("Profiles").Rows(RowIn dex).Item(0)
Next

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

How does one do this?

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

Oct 7 '06 #3
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" <Ke**********@discussions.microsoft.comwrote in message
news:CA**********************************@microsof t.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.Cou nt - 1

DropDownProfiles.Items.Add(WizoProfilesDataSet.Ta bles("Profiles").Rows(RowIndex).Item(1))
DropDownProfiles.ValueMember =
WizoProfilesDataSet.Tables("Profiles").Rows(RowIn dex).Item(0)
Next

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

How does one do this?

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

Oct 7 '06 #4
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" <Ke**********@discussions.microsoft.comwrote in message
news:CA**********************************@microsof t.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.Tab les("Profiles").Rows(RowIndex).Item(1))
DropDownProfiles.ValueMember =
WizoProfilesDataSet.Tables("Profiles").Rows(RowInd ex).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(RowInd ex).Item(0)
but there is no such member or property.

How does one do this?

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com


Oct 7 '06 #5
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.
--
Anil Gupte
www.keeninc.net
www.icinema.com

"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.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" <Ke**********@discussions.microsoft.comwrote in message
news:CA**********************************@microso ft.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.Cou nt - 1

DropDownProfiles.Items.Add(WizoProfilesDataSet.Ta bles("Profiles").Rows(RowIndex).Item(1))
DropDownProfiles.ValueMember =
WizoProfilesDataSet.Tables("Profiles").Rows(RowIn dex).Item(0)
Next

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

How does one do this?

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com



Oct 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
18304
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
6
3364
by: Kurt Mang | last post by:
Hi all -- I hate to yell "BUG", but can anyone explain why I cannot get a dropdown list / checkboxlist to recognise the Value property of a ListItemCollection (created at runtime) that I bind...
5
2654
by: DC Gringo | last post by:
I have a dropdownlist that, upon form submission, I'd like to maintain the selected value when I get my result...how do I do that? <asp:dropdownlist Font-Size="8" id="ddlCommunities"...
2
2112
by: Billy | last post by:
Change DataGrid EditControl On Data Value Hi, I have a datagrid, and on editing, I want to change the control in the third colunm based on the value of the first column. The value in the...
1
10379
by: Ben | last post by:
I have a formview with a few dropdownlists (software version, database version, etc). When a software version is selected, the database version dropdownlist updates itself accordingly. When in...
3
1237
by: Steve | last post by:
I have a databound dropdown in my page. I want to make one of the values the default value. Any ideas? Just to explain further, I have also appended one item to the dropdown, using the...
5
27367
by: =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?= | last post by:
Hello. I am reading a value from a table and trying to determine if that value exists in a list of values associated with a dropdownlist. If so, I select the value, otherwise, I don't. I haven't...
2
2053
by: mervyntracy | last post by:
Hi There, I have recently started coding in asp.net (just 2 and a half days now). I am writing a simple test app that gets data from a data base and displays the value perfectly in the drop down...
3
2779
by: John | last post by:
I have two dropdown lists that I have bound to a datatable and set the DataTextField and DataValueField for. Both lists show the values I expect from the database. However, when I need to access...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.