获取排在数据网格 [英] Get row in datagrid

查看:110
本文介绍了获取排在数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让行是这样的:

DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(i);
TextBlock cellContent = dataGrid.Columns[0].GetCellContent(row) as TextBlock;

但我只拿到了。是否有另一种解决方案?我在做什么错了?

But I only got null. Is there another solution? What am I doing wrong?

我想从我的细胞中获取数据。我的细胞是复选框。

I want to get data from my cells. My cells are checkboxes.

推荐答案

这取决于如何/当你正试图获得这些数据。 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.

这篇关于获取排在数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆