简体   繁体   中英

Does a WPF `DataRow` have a property for the ID or PK of the row item?

I've done some looking around, and it seems there is no apparent means of telling a WPF DataGrid which property in the item bound to a DataRow , and nor is there a special field on the DataRow for this property. Using a special 'Key' column that is normally hidden is hideously clumsy, and adding such a property to the grid somehow is a no-fun endeavour. I'm not being unreasonable here - most other grids have such functionality.

You should not need it. Using databinding you bind a collection of Objects to the DataGrid. Usually you handle directly the underlying collection.
Ie if you need the ID of the 5th row just get the 5th element in the underlying collection and extract the ID.
Also you can cast SelectedItem to your collection item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM