NemesisProg NemesisProg - 1 year ago 154 Question

filter a datagridview using linq to entities

I just found linq to entities. I decided to use it in my program.

I have a database with Sql server 2014. I imported my database with the help of " entity data model".

Until then everything is fine, I created a context and I binded it on a bindingsource and the bindingsource is binded to my datagridview.

The problem is that when I come to filter my datagridview with the help of bindingsource.filter, nothing happens.

bindingsource.DataSource = entitiesCOOP.completeInventory.ToList()
dgv.DataSource = bindingsource

bindingsource.Filter = String.Format("description LIKE '" & txt_description.Text & "%'")

Did I make a mistake somewhere? Or is it the fact that it is a list that does not allow to filter?

Otherwise, would there be another way I could use with the help of entity framework to filter a datagridview?

Answer Source

Filter the incoming request. I did not include the Like operator since you had no wildcards which would be the same as equals - roughly.

bindingsource.DataSource = entitiesCOOP.completeInventory.
                           Where(Function(ci) ci.description = txt_description.Text).ToList
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download