使用组合框填充另一个组合框 [英] Using a combo box to populate another combobox

查看:83
本文介绍了使用组合框填充另一个组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码填充cmblocations组合框:

With cmbLocations
               .DataSource = dsLocations.Tables("tbl_locations")
               .DisplayMember = "location"
               .ValueMember = "id"
               .SelectedIndex = 0
           End With


我想使用.ValueMember查询数据库,然后可以填充其他组合框. ;要获取其当前选定的ID,则可以对该ID进行数据库查询,并获取该ID的值并将其分配给另一个CMB.


您可以尝试此
如果cmbLocations.SelectedIndex> 0然后
昏暗的dt =新的数据表
''致电DataAccess获取新结果集
dt = obj.GetList(cmbLocations.SelectedValue)
带有ComboBox1
.DataSource = dt
.DisplayMember =位置"
.ValueMember ="ID"
.SelectedIndex = 0
结尾为
如果结束


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.

解决方案

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.


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


这篇关于使用组合框填充另一个组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆