Click here to Skip to main content
11,719,903 members (85,568 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
I want to show Data Gridview contents as per the selection of Combo box value.

E.g: I have Supplier combo box , as per the value I am selecting from it related information of supplier will display in Data Gridview control in .net.
Posted 4-Dec-12 4:06am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This comes down to getting the value of the combobox and putting it into an appropriate SQL SELECT statement to get the database information into a datatable. THen you just set the DGV DataSource property to the datatable returned.
Yogi ,Pune at 4-Dec-12 23:02pm
Please provide code for the same.
Dave Kreskowiak at 5-Dec-12 0:20am
Nope. I'm not writing you're code for you. It's not that hard. You handle the SelectedValueChanged event of the Combo and use the Value in your SQL as a parameterized query. I just gave you everything you need to Google and do a little research on your own.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I already tried following code but system give me Error on sql query Object reference not set to an instance of an object

Dim ds As New DataSet

Str = Select p.PO_no,p.Date,s.Sup_name from PO_Header p, Supplier_Master s Where p.Sup_no = '" & cmbItemName.SelectedValue.ToString() & "'"

Dim da As New SqlDataAdapter(str, SetCon())
da.Fill(ds, "New")
<pre lang="vb">DataGridView1.DataSource =ds.Tables(0).DefaultView</pre>

Is there is any thing wrong in my code.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

1. Create sub
Private Sub refresh_data()
  Dim Ds as new dataset
  Dim Query as String = "Select * from Supplier_master where Supplier_ID = '" & cmb_supplierID.text & "'"
  Dim SQL_Adapter as new SqlDataAdapter(Query,Connection)
  DataGridView1.DataSource = Ds.Tables(0)
End Sub

2. in event combo box selected change
call refresh_data()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 685
1 OriginalGriff 255
2 F-ES Sitecore 225
3 Suvendu Shekhar Giri 140
4 Maciej Los 100
0 Sergey Alexandrovich Kryukov 1,869
1 OriginalGriff 770
2 F-ES Sitecore 640
3 Maciej Los 609
4 Richard MacCutchan 540

Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2015
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