开发者

databinding DataGrid to a List<object[]>

I have a List<object[]> MyCollection which is a result of a SELECT SQL query.

Each object[] represents a row in th开发者_如何学Pythone query result, and the length of the array will vary for different queries.

I have the name of the column headers in a separate List<string> MyHeaders.

I want to databind MyCollection to a DataGrid with the header of the columns from MyHeaders, and autogenerate the columns.

The reason I want to use AutoGenerateColumns is because I want the Datagrid to reconize the DataTypes of each object, and use the appropriate Column Templates for each DataType.

Thanks!


If you're stuck and need to get on: use a dataset/ datatable. Ancient but they still work fine! If you want to know if it can be done, i don't know. Most examples of binding to an IList I've seen manually loop and create columns.

Regards GJ


Don't use a list for the headers, use a dictionary and use the property names as the keys and put the description as the values. Do a normal blah.DataSource = List and DataBind(). In your itemdatabound event replace the headers with your description by searching the dictionary with something like this:

foreach col in grid.Columns { col.Name = dic[col.Name].Value; }

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜