I want to filter through my DataGridView data. My DataGridView's DataSource is bound to a BindingSource
. The BindingSource contains a list of objects from my clsBillHeader
class.
Here is the first bit of code:
Dim bSource As New BindingSource
bSource.DataSource = clsBillHeader.GetAll()
dgvBills.DataSource = bSource
bSource.Filter = "JobNumber Like '100%'" //Filter doesn't actually work
GetAll()
Public Shared Function GetAll() As List(Of clsBillHeader)
Dim mycn As New SqlConnection(connection)
Dim mycmd As New SqlCommand("SELECT * FROM Headers", mycn)
mycn.Open()
Dim myreader As SqlDataReader = mycmd.ExecuteReader
Dim myList As New List(Of clsBillHeader)
While myreader.Read
Dim item As New clsBillHeader()
SetByReader(myreader, item) //Sets all values correctly (such as forein keys)
myList.Add(item)
End While
mycn.Close()
Return myList
End Function
This successfully returns all my values needed as you can see in this screenshot:
The problem is it doesn't filter through anything ... my JobNumber Like '100%'
doesn't seem to be filtering at all. As seen below:
I should just be getting the first two numbers but it returns everything else ...
Why am I not using DataView to use filtering?
Well, DataView would cause me to use a DataTable that is directly bound to the SQL table. Some values in my table are foreign keys and would need to be transformed into something more meaningful than integers.
Ex: FK_Author = 1
would be the value in the DataTable. Instead, I use my SetByReader to transform it into Author = "Alex"
. That's why I want to use a BindingSource.
All I need is to filter through a DataGridView bound to a class of clsBillHeaders
. Has anyone had the same problem?
EDIT
Take a look at this screenshot. Apparently it doesn't support Filtering ...
Why does my BindingSource variable have this by default?