Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following code which populates the dropdown lists from the database. This works fine. Now, when the user selects a particular days from the list, I want to get the Days Id of the selected employee. i.e. I need to get the Dayid value. I can do this if the Dayid is loaded in the dropdown list, but in this case only the days are displayed. Please let me know how I can get the Dayid value even though it is not loaded in the dropdown list.

This is how i load the listbox from the database:
For Each dr As DataRow In m_dtDelayedDeliveryDays.Rows
            Me.cmbDelayedDeliveryDays.Items.Add(dr("DeliveryDelayDays"))
        Next

m_dtDelayedDeliveryDays is my datatable.

Please help
Posted
Updated 15-Feb-13 9:29am
v3
Comments
joshrduncan2012 15-Feb-13 14:50pm    
Are you referring to the position of the element in the combobox (i.e. first position, second position, third, etc?)
vidkaat 15-Feb-13 14:51pm    
no i am new to VB so i dont have any clue how to do that...
joshrduncan2012 15-Feb-13 14:55pm    
First of all, your header is a little misleading. You mention comboboxes in your header but your question refers to listboxes. Make sure that is clear.

I strongly urge you to research listbox and their associated properties. There is a command provided that will return the position of the element in the listbox.
vidkaat 15-Feb-13 14:57pm    
its a combo dropdowl list box.
joshrduncan2012 15-Feb-13 14:59pm    
What version of Visual Studio are you using? I've never heard of a listbox having drop down capabilities.

1 solution

You actually need to add the ListItem separately, instead of in the constructor. For example:

VB
For Each dr As DataRow In m_dtDelayedDeliveryDays.Rows
   Dim tempList as New ListItem
   tempList.Text = dr("DeliveryDelayDays")
   tempList.Value = dr("DeliveryDelayDaysID")
   Me.cmbDelayedDeliveryDays.Items.Add(tempList)
Next


This is from memory but that should be pretty close. You'll have to specify what the ID is.
 
Share this answer
 
Comments
vidkaat 15-Feb-13 14:55pm    
I dont want to add the id to the drop down list i want the corresponding id of the selected day from the drop down list.
ZurdoDev 15-Feb-13 14:57pm    
Correct. You need to put the ID into the ListItem value property and what you want the user to see in the ListItem.Text property. Are you familiar with the dropdown's having both a value and a text?
vidkaat 15-Feb-13 14:58pm    
Nope i am not.
ZurdoDev 15-Feb-13 15:04pm    
So, a drop down item has 2 values, the actual text you see and then there is a value behind the scenes that is in html but that the user does not see. This is a perfect example of when you use it. You show the user the Day and then you get the actual value. Maybe looking at http://www.w3schools.com/tags/tag_select.asp will help.
vidkaat 15-Feb-13 15:05pm    
no my combo has only one value ie...days

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900