Click here to Skip to main content
12,063,452 members (70,960 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
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
Posted 7-Nov-12 6:24am
Edited 7-Nov-12 19: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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

use this
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!
Smile | :)
  Permalink  
Comments
Sunil Bansode 8-Nov-12 22:24pm
   
Thanks...!!!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Do you have your DisplayMember and ValueMember properties set on the comboboxes?
  Permalink  
Comments
Sunil Bansode 7-Nov-12 12:08pm
   
yes i have displaymember and valuemember also
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

I would rather suggest you to write the selection code on SelectedValueChange event of Combobox

Amit Saraf
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160204.4 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100