Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"

VB
 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
Posted
Updated 7-Nov-12 18:14pm
v5
Comments
Jason Gleim 7-Nov-12 11:38am    
Is this a WinForms application or a WPF application? What error(s) are you getting? You've brought your car to the mechanic but said, 'something is broke' without telling us what it is.
__TR__ 7-Nov-12 12:21pm    
Looks like your select statement is only returning Item and not the ID column for cmb2.
Modify your query to include ID column.

use this
VB
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!
:)
 
Share this answer
 
Comments
Sunil Bansode 8-Nov-12 22:24pm    
Thanks...!!!
Do you have your DisplayMember and ValueMember properties set on the comboboxes?
 
Share this answer
 
Comments
Sunil Bansode 7-Nov-12 12:08pm    
yes i have displaymember and valuemember also
I would rather suggest you to write the selection code on SelectedValueChange event of Combobox

Amit Saraf
 
Share this answer
 
Comments
Sunil Bansode 8-Nov-12 22:25pm    
Thanks...!!!

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