|
-
Aug 29th, 2012, 02:28 PM
#1
Thread Starter
Junior Member
Filter DataGrid using Combobox
In a simple form (Form1) I have one combobox (ComboBox1) and one datagrid (DataGridView1).
Combobox1 data source is a Access 2010(.accdb) table (tblCoustomers; CID is the ValueMember, CName is the DisplayMember)
DataGridView1 data source is from the same database (tblInvoice)
tblInvoice have those columns:
InvID, InvNumber, InvDate, CID
When I change the value in the ComboBox , i need that the DataGridView to show only the informations corresponding to combobox ValueMember.
Code:
Private Sub ComboBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Me.BindingSource1.Filter = String.Format("CID LIKE '{0}%'", ComboBox1.ValueMember)
DataGridView1.Visible = True
End Sub
I have also tried, without success:
Me.BindingSource1.Filter = String.Format("Field1 LIKE '{0}%' OR Field2 LIKE '{0}%'",Me.ComboBox1.ValueMember)
Me.BindingSource1.Filter = String.Format("Name LIKE '%{0}%'", Me.ComboBox1)
Me.BindingSource1.Filter = "CID = " & ComboBox1.ValueMember
Me.BindingSource1.Filter = "CID = '" & ComboBox1.ValueMember & "'"
Me.BindingSource1.Filter = "CID Like '%" & ComboBox1.ValueMember & "%'"
The combobox show the DisplayMembers correctly, the DataGrid show ALL the data, but I can't manage to filter those data.
I use VB 2010
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|