views:

1301

answers:

4

Hi, I have never used datagrids and such, but today I came across a simple problem and decided to "databind" stuff to finish this faster, however I've found that it doesn't work as I was expecting.

I though that by doing something as simple as:

 var q = from cust in dc.Customers
         where cust.FirstName == someString
         select cust;

 var list = new BindingList<Customer>(q.ToList());
 return list;

Then using that list in a DataGridView1.DataSource was all that I needed, however, no matter how much I google, I can't find a decent example on how to populate (for add/edit/modify) the results of a single table query into a DataGridView1. Most samples talk about ASP.NET which I lack, this is WinForms.

Any ideas?

I've came across other posts and the GetNewBindingList, but that doesn't seem to change much.

What am I missing (must be obvious)?

Thanks in advance.

Martin.

+2  A: 

You can just bind the IQueryable result to the DataGridView, not sure why you converting it to a BindingList, is there a specific reason for that?

Lazarus
To provide two way binding so that changes in the DataGridView can be notified?
Kev
Well, no reason. As I've mentioned I'm 100% new to DataGrids, that's an example I found somewhere in google land. :S (But it doesn't work)
Martín Marconcini
A: 

You might have a look at the TableList<T> from this post - based on BindingList<T>, but with hooks into the data-context.

Marc Gravell
Oh, I've seen that post before (had it open in one of the Tabs), I just realized it was your post! :)Will re-read it and ask if I have questions. Thanks.
Martín Marconcini
A: 

Just bind it.

    var q = from cust in dc.Customers
            where cust.FirstName == someString
            select cust;
    DataGridView1.DataSource = q

No need to convert it to list.

Waheed
A: 

What I really was looking for was for the simplest way, I found it: here.

Thanks to all who replied and gave ideas.

Martín Marconcini