Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Linq, Datagridviews and Bindingsources

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Søren Reinke - 20 Jan 2008 11:09 GMT
Hi there.

I am trying to get to know LINQ in combination with a bindingsource and
a datagridview.

In the framework we have at work we have created a usercontrol to do
filtering via textboxes on a datagridview. Therefore we databind through
a bindingsource.

But when i load the data from the database via LINQ instead of through a
datatable, i can't seem to get the filter property to work on the
bindingsouce. I can set it but absolutly nothing happens.

Do i have to do something special to get it to work with LINQ, or is it
simple not possible ?

If you need some source, i'll gladly make an example and post it.

In words, what i do is.

The datagridview has the bindingsource as datasource,
I load data from the database via LINQ.
Then i set the columns on the datagridview to be those contained in the
data from the database (primary key, a name).
I set the database to the 'var' which contains the LINQ's request result.

If i run the program i get the data shown, and i can sort when clicking
on the columnheaders and all that.

But if i set the filter with something like:

bindingsource.Filter="Key>25";

Absolut nothing happens, it still shows rows in the datagrid where the
primary key 'Key' is lower or equal to 25.

What is important is that the '25' in the above example can be a number
coming from a user input in the program.

Hope you can help.

Best regards
Søren Reinke
www.Dykkeren.dk
William Stacey [C# MVP] - 20 Jan 2008 16:06 GMT
TMK, only collections that support IBindingListView can be used with Filter.
As a work around you can filter the Entity like:

           this.localTimeEntryBindingSource.DataSource =
db.LocalTimeEntries.Where(i=>i.Posted==false);

hth

W

Hi there.

I am trying to get to know LINQ in combination with a bindingsource and
a datagridview.

In the framework we have at work we have created a usercontrol to do
filtering via textboxes on a datagridview. Therefore we databind through
a bindingsource.

But when i load the data from the database via LINQ instead of through a
datatable, i can't seem to get the filter property to work on the
bindingsouce. I can set it but absolutly nothing happens.

Do i have to do something special to get it to work with LINQ, or is it
simple not possible ?

If you need some source, i'll gladly make an example and post it.

In words, what i do is.

The datagridview has the bindingsource as datasource,
I load data from the database via LINQ.
Then i set the columns on the datagridview to be those contained in the
data from the database (primary key, a name).
I set the database to the 'var' which contains the LINQ's request result.

If i run the program i get the data shown, and i can sort when clicking
on the columnheaders and all that.

But if i set the filter with something like:

bindingsource.Filter="Key>25";

Absolut nothing happens, it still shows rows in the datagrid where the
primary key 'Key' is lower or equal to 25.

What is important is that the '25' in the above example can be a number
coming from a user input in the program.

Hope you can help.

Best regards
Søren Reinke
www.Dykkeren.dk
Søren Reinke - 20 Jan 2008 16:35 GMT
> TMK, only collections that support IBindingListView can be used with
> Filter. As a work around you can filter the Entity like:
[quoted text clipped - 3 lines]
>
> hth

Thanks for the tip, ill try it tommorov :)

/Søren

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.