How can I get a value of a property from an anonymous type?

后端 未结 12 1292
南旧
南旧 2020-12-24 08:34

I have a datagrid populated by a Linq query. When the focused row in the datagrid changes I need to set a variable equal to one of the properties in that object.

I t

12条回答
  •  渐次进展
    2020-12-24 09:36

    As JaredPar guessed correctly, the return type of GetRow() is object. When working with the DevExpress grid, you could extract the desired value like this:

    int clientId = (int)gridView.GetRowCellValue(rowHandle, "ClientId");
    

    This approach has similar downsides like the "hacky anonymous type casts" described before: You need a magic string for identifying the column plus a type cast from object to int.

提交回复
热议问题