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
祝你成功!
展开全部
.如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="表.班级编号"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询