问题描述
尊敬的先生,
我正在使用vb.net开发Windows应用程序,
在其中我有3个comboBox控件(cmb1,cmb2,cmb3).
在表单加载事件中..cmb1将附加到数据表
在运行时,我从cmb1中选择值之一.
取决于cmb1的值,新的SQL查询将形成表格,然后cmb2将填充数据..
就像明智的cmb3一样,数据将取决于cmb2的值来填充..
请帮我谢谢..
我正在使用以下代码..
但无法正常工作,但出现错误.."System.Data.DataRowView"
Respected Sir,
I am developing windows application using vb.net,
In which i have 3 comboBox controls(cmb1,cmb2,cmb3) .
At form load event.. cmb1 will be attached to datatable
At runtime i select one of the value from cmb1.
depends on that value of cmb1 new sql query will be form and then cmb2 will be filled with data..
and like wise cmb3 will be filled with data depends on value of cmb2..
please help me thank you..
i m using following code..
but not working getting errors.. "System.Data.DataRowView"
Private Sub cmb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb1.SelectedIndexChanged
Sql = "SELECT * from stock where brand=" & cmb1.SelectedValue
ds = objStock.ShowAllRequiredInStocks(Sql)
cmb2.DataSource = ds.Tables(0)
cmb2.displaymember="Item"
cmb2.valuemember="ID"
End Sub
Private Sub cmb2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb2.SelectedIndexChanged
Sql = "SELECT * from stock where item=" & cmb2.SelectedValue
ds = objStock.ShowAllRequiredInStocks(Sql)
cmb3.DataSource = ds.Tables(0)
cmb3.displaymember="Price"
cmb3.valuemember="ID"
End Sub
推荐答案
Private Sub cmb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb1.SelectedIndexChanged,cmb1.SelectedValueChanged
Try
if IsNumber(cmb1.selectedValue) Then
Sql = "SELECT * from stock where brand=" & cmb1.SelectedValue
ds = objStock.ShowAllRequiredInStocks(Sql)
cmb2.DataSource = ds.Tables(0)
cmb2.displaymember="Item"
cmb2.valuemember="ID"
End If
Catch
End Try
End Sub
Private Sub cmb2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb2.SelectedIndexChanged,cmb2.SelectedValueChanged
Try
If IsNumber(cmb2.SelectedValue) then
Sql = "SELECT * from stock where item=" & cmb2.SelectedValue
ds = objStock.ShowAllRequiredInStocks(Sql)
cmb3.DataSource = ds.Tables(0)
cmb3.displaymember="Price"
cmb3.valuemember="ID"
End If
Catch
End Try
End Sub
祝您编码愉快!
:)
Happy Coding!
:)
这篇关于如何从第一个组合框值的选定值向组合框填充数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!