deanlee17
asked on
Filtering a datagrid
Hi guys,
I need to filter a datagrid by one specific column. How can I do this in code? The grid is already loaded with data.
Thanks,
Dean.
I need to filter a datagrid by one specific column. How can I do this in code? The grid is already loaded with data.
Thanks,
Dean.
You can use a dataview to filter the results, but how have you filled the datagridview?
ASKER
I have a dataset and im just filling the grid with....
Dim testobj = CountPartsDataSet.Counterf eitParts
Me.flxCounterfeit.ItemsSou rce = testobj
Ideally I want the datagrid filtering as a user types into a textbox, how is this possible?
Dim testobj = CountPartsDataSet.Counterf
Me.flxCounterfeit.ItemsSou
Ideally I want the datagrid filtering as a user types into a textbox, how is this possible?
Something like this on TextChanged event:
Dim dv As DataView = DirectCast(Me.DataGridView 1.DataSour ce, DataView)
dv.RowFilter = String.Format(" columnNameToFiler LIKE '%{0}%'", Me.txtFilterTextBox.Text)
Dim dv As DataView = DirectCast(Me.DataGridView
dv.RowFilter = String.Format(" columnNameToFiler LIKE '%{0}%'", Me.txtFilterTextBox.Text)
ASKER
Error:
Unable to cast object of type 'CounterfeitPartsDataTable ' to type 'System.Data.DataView'.
My code looks like this....
Dim dv As DataView = DirectCast(Me.flxCounterfe it.ItemsSo urce, DataView)
dv.RowFilter = String.Format(" columnNameToFiler LIKE '%{0}%'", Me.txtFilterTextBox.Text)
Unable to cast object of type 'CounterfeitPartsDataTable
My code looks like this....
Dim dv As DataView = DirectCast(Me.flxCounterfe
dv.RowFilter = String.Format(" columnNameToFiler LIKE '%{0}%'", Me.txtFilterTextBox.Text)
Is it an WPF application?
If so try this instead http://stackoverflow.com/questions/4166403/wpf-datagrid-filter
If so try this instead http://stackoverflow.com/questions/4166403/wpf-datagrid-filter
ASKER
Btw ive now added my own column name, so....
Dim dv As DataView = DirectCast(Me.flxCounterfe it.ItemsSo urce, DataView)
dv.RowFilter = String.Format(" PartNumber LIKE '%{0}%'", Me.txtFilterTextBox.Text)
Same error
Dim dv As DataView = DirectCast(Me.flxCounterfe
dv.RowFilter = String.Format(" PartNumber LIKE '%{0}%'", Me.txtFilterTextBox.Text)
Same error
ASKER
Yes its WPF, your example is in C#, i need it in VB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CodeCruiser, you absolute legend.
@deanlee17,
You had to change only a small thing from the code I have posted and I didn't had any points for that !!!
I was testing the solution I provided (that is for Winforms) in WPF.
Thanks!
You had to change only a small thing from the code I have posted and I didn't had any points for that !!!
I was testing the solution I provided (that is for Winforms) in WPF.
Thanks!
ASKER
@jpaulino,
How was I to know you were testing the solution? When I said it was WPF I thought maybe you didnt know the solution.
Sorry about this.
How was I to know you were testing the solution? When I said it was WPF I thought maybe you didnt know the solution.
Sorry about this.
You only had ".DefaultView" to the code I have provided !!!
Since you can split points I think it's a little unfair.
Since you can split points I think it's a little unfair.
ASKER
jpaulino, tell me exactly what you want me to do.
I don't need the points, that’s not the problem, but since you have the option of accept multiple answers you should do it and split the points from the persons that tried to help you (I have posted 95% of the code you need).
We don’t earn nothing with this, we just like to help and this (points) is a way to recognize it ;)
We don’t earn nothing with this, we just like to help and this (points) is a way to recognize it ;)
ASKER
Yes i know about splitting points and do usually. I just didnt this time. Sorry about that, look out for my next question and we can sort something out ;)