I'm struggling with being able to filter a bindingsource. I have a form with a datagridview (Player_InfoDataGridView). I have an event that triggers when the user double clicks on a specific record within the datagridview. That event opens another form (Tracking_List) with textboxes containing data from a bindingsource. The form has a bindingnavigator that moves from one record to the next. I need to be able to filter that form based on certain fields from the datagridview on the first form. I have assigned variables to capture the values of the certain fields to use in the filter based on the current row that the user double clicks on. However, I cannot find the correct filter code that works. Here is what I have so far:
Private
Sub CellButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Player_InfoDataGridView.DoubleClickTracking_List.Show()
FilterYear = Player_InfoDataGridView.CurrentRow.Cells("DataGridViewTextBoxColumn7").Value
FilterSet = Player_InfoDataGridView.CurrentRow.Cells("DataGridViewTextBoxColumn8").Value
FilterNumber = Player_InfoDataGridView.CurrentRow.Cells("DataGridViewTextBoxColumn9").Value
FilterCondition = Player_InfoDataGridView.CurrentRow.Cells("DataGridViewTextBoxColumn10").Value
Tracking_List.PlayerInfoBindingSource.Filter = Tracking_List.Year.Text & "='" & FilterYear & "'" And Tracking_List.Make.Text & "='" & FilterSet & "'" And Tracking_List.CardNumber.Text & "='" & FilterNumber & "'" And Tracking_List.Condition.Text & "='" & FilterCondition & "'"
Me.Close()
End Sub
What would be the correct code for the Tracking_List.PlayerInfoBindingSource.Filter
Thanks,
John

Filter Problem
A.Russell
Andrej:
Thank you. I'll try that and see if it works. However, just to clarify, I am not trying to filter a datagridview. The criteria for the filter is coming from a datagridview, but what I am trying to filter is data displayed on a form through textboxes. In other words, the control Tracking_List.Year.Text would equal FilterYear, Tracking_List.Make.Text would equal FilterSet, etc. I have been able to filter this data from a form containing comboboxes and it works. I just don't know how to do it from a form containing a datagridview. I'll let you know how your suggestion works. Hopefully it will. Thanks.
John
Annihil8
Hi,
Filter property lets you filter your data in a datasource (datatable), so you should use Column names in the Filter expression (It's like building WHERE part of the SQL SELECT statement). Something like:
Tracking_List.PlayerInfoBindingSource.Filter = "Year=" & FilterYear & " And Make='" & FilterSet & "' And Number=" & FilterNumber & " And Condition='" & FilterCondition & "''".
This should result in a string:
Year=2006 And Make='XXX' And Number=5 And Condition='Mint'
In the above code, I assumed that the column names in your datatable are named Year, Make, Number and Condition. Please make appropriate changes if they are not. Also note I didn't include quotation mark with columns Year and Number, because I assumed they are integers, which don't need to be quoted.
Andrej
Brian OByrne
Andrej
Well, I stand corrected. Your code in fact did work. I guess that is why guys like you are on here helping people. Thanks! In looking at your code versus what I had been trying to do, I think the fact that you include the 'And' within the quotes was the difference. When I was keeping the 'And' out of the quotes, I was getting an error something like "cannot convert string to 'Long'".
Thanks again,
John
Santhoo
Yes, the filter property expect's a string value, containing the condition to filter the data with. You left your AND's out of the string, which resulted in the expression like ["something" And "something"], with And here being the logical operator. And since logical operators only work with numbers, not strings, the compiler threw that error...
Andrej