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

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.
 
Share this answer
 
Comments
Yogi ,Pune 4-Dec-12 23:02pm    
Please provide code for the same.
Dave Kreskowiak 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.
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.
 
Share this answer
 
1. Create sub
VB
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)

  SQL_Adapter.fill(Ds)
  DataGridView1.DataSource = Ds.Tables(0)
End Sub


2. in event combo box selected change
VB
call refresh_data()
 
Share this answer
 
v2

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