且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取数据网格中的行

更新时间:2023-02-25 20:53:42

这取决于您尝试获取此数据的方式/时间.WPF 更适合通过绑定在 ItemsSource 中的对象访问数据.因此,如果您的 ItemsSource 是 MyObject 的列表,那么特定行的类型将是 MyObject 而不是纯 DataRow.

This depends on how / when you are attempting to get this data. WPF is more geared towards accessing the data by the objects bound in the ItemsSource. So, if your ItemsSource is a List of MyObject, then the specific row will be of type MyObject instead of a pure DataRow.

如果您通过点击来访问数据,您可以执行以下操作:

If you are accessing the data by means of clicking on it, you can do something like this:

var currentItem = myDataGrid.SelectedItem as MyObject;

现在,您拥有当前 MyObject 的原始预期形式,而不是在网格上进行选择.

Now, you have the current MyObject in it's originally intended form rather than picking at the grid.