开发者

Problem displaying a linq query in a datagridview

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()?


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();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜