views:

30

answers:

1

Hello: I am working on a C# project that reads an XML file and returns a list of lists. When I want to display a list I do this:

IEnumerable<Foo> myFooQuery = from t in myLists.SelectMany( l => l.bar)
                              orderby t.StartTime descending
                              select t;
dataGridView1.DataSource = myFooQuery.ToList();

My problem is that when I do it that way, you can't click on the column header to sort the datagridview. I tried myFooQuery.AsQueryable(), but then nothing shows up in the datagridview even though the query count is what I expect. Am I just missing something obvious, or do I have to use .Tolist()?

+3  A: 

You could try:

EnumerableRowCollection<DataRow> myFooQuery = from t in myLists.SelectMany( l => l.bar)
                              orderby t.StartTime descending
                              select t;

DataView myDataView = myFooQuery.AsDataView();

dataGridView1.DataSource = myDataView;

EDIT - commented out line

//dataGridView1.DataBind();

Ardman
I just tried to do this, and I am using Visual C# 2010, and I do not have a dataGridView1.DataBind().
Mark W
Sorry, didn't mean to include that. Have you tried it with out?
Ardman
yes, that does it. Thanks
Mark W