Click here to Skip to main content
15,897,094 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using this code to populate the cmblocations combobox :
With cmbLocations
               .DataSource = dsLocations.Tables("tbl_locations")
               .DisplayMember = "location"
               .ValueMember = "id"
               .SelectedIndex = 0
           End With

I would like use the .ValueMember to query the database, then i can populate other combo box.
Posted
Updated 30-May-11 21:53pm
v2
Comments
Simon_Whale 31-May-11 4:49am    
do you want the selected item to move to the new combo box? or do you have a different logic that needs to be used?
joseph k 31-May-11 5:00am    
Yes, i want to use a selected item as a value to search for a record in another table called Regions, Am using its 'id' as Foregn key in table Regions , Then i load the results on another combo box

Thanks
Karwa_Vivek 31-May-11 5:19am    
hi Joseph ..got the Solution ?
joseph k 31-May-11 6:33am    
Yes i got the answer , Thanks very much
Karwa_Vivek 3-Jun-11 5:41am    
If you Got it
here..Remember To
Mark Your Solution
So that it can help others
Also.it's Simple Just Click the Green
button.
Thanks

you can use string ID = cmbLocations.SelectedValue.ToString(); to get its current selected id then you can fire a database query for this id and get values for this id and assign it to another CMB.
 
Share this answer
 
Comments
Simon_Whale 31-May-11 5:47am    
Simple but good answer
joseph k 31-May-11 6:34am    
Great i managed to nail it properly... Thanks
prem shanker verma 3-Jun-11 5:14am    
right
just create a function having one argument(id) and call it on selectedIndex change, as
fillSecondCombo(ddl1.selectedValue.toString())
You can try this
If cmbLocations.SelectedIndex > 0 Then
Dim dt = New DataTable
'Call DataAccess for New Result set
dt = obj.GetList(cmbLocations.SelectedValue)
With ComboBox1
.DataSource = dt
.DisplayMember = "location"
.ValueMember ="ID"
.SelectedIndex = 0
End With
End If
 
Share this answer
 

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