获取行我试图让行这样的:在数据网格
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(i);
TextBlock cellContent = dataGrid.Columns[0].GetCellContent(row) as TextBlock;
但我只得到了null
。还有其他解决方案吗?我究竟做错了什么?
我想从我的细胞中获取数据。我的单元格是复选框。
获取行我试图让行这样的:在数据网格
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(i);
TextBlock cellContent = dataGrid.Columns[0].GetCellContent(row) as TextBlock;
但我只得到了null
。还有其他解决方案吗?我究竟做错了什么?
我想从我的细胞中获取数据。我的单元格是复选框。
这取决于您试图获取此数据的方式/时间。 WPF更适合通过ItemsSource中绑定的对象访问数据。因此,如果您的ItemsSource是MyObject的列表,那么特定的行将是MyObject类型而不是纯DataRow。
如果您正在访问通过点击它的装置中的数据,你可以做这样的事情:
var currentItem = myDataGrid.SelectedItem as MyObject;
现在,你有电流为MyObject在它原本打算形式,而不是在网格采摘。
这是旧的,但如此之大。非常感谢! – VixinG
for(int row =0; row < dg_CountInventory.Rows.Count; row ++) //Loop through each row
{
//Provide the Column Index and row as in Loop
TextBlock b = dg_CountInventory.Columns[1].GetCellContent(dg_CountInventory.Items[row ]) as TextBlock;
}
dg_CountInventory是通过所有的记录 存在于数据网和手机/塔,只要我的网Name.This代码回路。#
['DataGrid'](https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid%28v=vs.110%29.aspx)没有'行'属性。 –
检查该解决方案 http://stackoverflow.com/questions/1976087/wpf-datagrid-set-selected-row/5483614#5483614 –