vb.net中的combobox数据绑定问题
在vb.net(2005)中,怎么将combobox中text属性与表中的字段绑定起来,而且combobox的绑定字段随另一个combobox的选择值不同而可供选择的值也...
在vb.net(2005)中,怎么将combobox中text属性与表中的字段绑定起来,而且combobox的绑定字段随另一个combobox的选择值不同而可供选择的值也不同.如combobox1是绑定专业编号的,combobox2是绑定班级编号的,当combobox1选择了1时,combobox2中可供选择的字段只能是专业1中所包含的班级编号.请给详细代码.(数据库已经连接好,只给绑定代码加思路即可.)
展开
2个回答
展开全部
使用SelectedIndexChanged事件
Private Sub cbxBigDept_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
dim strBM as string
strBM=cbxBigDept.selectedValue ' 获得当前大部门名称
Dim myConn as SqlConnection = new sqlconnection(".......")
myConn.Open()
Dim myCmd as string = "select 小部门 from 小部门表 Where 大部门='" & strBM & "'"
Dim myAdapter as SqlDataAdapter = new SqlDataAdapter(myCmd,myConn)
Dim myDataSet as DataSet = new DataSet
myAdapter.Fill(myDataSet)
Me.cbxSonDept.DataSource = myAdapter.Table(0)
Me.cbxSonDept.ValueMember = "小部门"
myConn.Close
End Sub
祝你成功!
Private Sub cbxBigDept_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
dim strBM as string
strBM=cbxBigDept.selectedValue ' 获得当前大部门名称
Dim myConn as SqlConnection = new sqlconnection(".......")
myConn.Open()
Dim myCmd as string = "select 小部门 from 小部门表 Where 大部门='" & strBM & "'"
Dim myAdapter as SqlDataAdapter = new SqlDataAdapter(myCmd,myConn)
Dim myDataSet as DataSet = new DataSet
myAdapter.Fill(myDataSet)
Me.cbxSonDept.DataSource = myAdapter.Table(0)
Me.cbxSonDept.ValueMember = "小部门"
myConn.Close
End Sub
祝你成功!
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
展开全部
.如combobox1是绑定专业编号的,combobox2是绑定班级编号的
dim mydataset as new dataset()
.....
combobox1.datasource=mydataset
combobox1.displaymember="表.专业编号"
combobox2.datasource=mydataset
combobox2.displaymember="表.班级编号"
dim mydataset as new dataset()
.....
combobox1.datasource=mydataset
combobox1.displaymember="表.专业编号"
combobox2.datasource=mydataset
combobox2.displaymember="表.班级编号"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询