Click here to Skip to main content
Rate this: bad
good
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
good
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.
  Permalink  
Comments
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
good
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.
  Permalink  
Rate this: bad
good
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)
 
  SQL_Adapter.fill(Ds)
  DataGridView1.DataSource = Ds.Tables(0)
End Sub
 
2. in event combo box selected change
call refresh_data()
  Permalink  
v2

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 9,108
1 OriginalGriff 8,186
2 CPallini 2,613
3 Richard MacCutchan 2,231
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2014
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