I generated an EF model (Database first) and DataSource following this tutorial http://msdn.microsoft.com/en-us/data/jj682076.aspx
On my form I created BindingSource (bsUsers) and bound DataGridView to it.
Here is how I load data on form startup:
_myDbContext = new MyDbContext();
_myDbContext.Users.Load();
bsUsers.DataSource = _myDbContext.Users.Local.ToBindingList();
It works, I can add and modify records using DataGridView and other bound controls.
But the thing I didn't figure out is how to filter data. For example I want to have textbox where I can type user name (or part of it) and it will hide all other records.
Looks like BindingList that is returned by ToBidingList() method doesn't support filtering?
I tried this
bsUsers.Filter = "Id = 1";
or
bsUsers.Filter = "Username like 'admin'";
But no effect. UPD: and bsUsers.SupportsFiltering
is false
.
I have googled but found only this topic MSDN topic where they suggest to filter data before loading (Users.Where(...).Load()
), and that's not what I need. I want to load all records and then allow to filter it.