开发者

How to get an Item from an auto-populated DataGrid?

I have a DataGrid that is automatically fed certain values from an LINQ-To-SQL-Source. The headers of the DataGrid are also auto-generated. I simply want one of the Cells of the currently selected item within the data-grid.

var a = TestGrid.SelectedCells[0].Item;

If I debug this I get a List containing all the v开发者_Python百科alues I need:

TestGrid.SelectedCells[0].Item{ Datum = {11.05.2011 00:00:00}, ID = 3, name = "db",Status = "Ready" }<Anonymous Type>

I have absolutely no idea how to select the second item(ID) from that anonymous type, and google isn't helping


The best option would be to create a type to hold your values and store that in your DataGrid. If you're only using it for display, the anonymous types are fine to use. The moment you need to use them for anything else, they are not so great.

If you really want to stick to anonymous types, the only option you have is to use reflection. If this is specifically a C# 4.0+ app, then using dynamic can make this somewhat easier.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜