我正在创建一个WPF应用程序,当用户单击DataGrid的某行时,我需要获取一个列值,并使用该值从数据库中获取数据。
我可以找到DataGridRow,但无法获取列值。这是我的代码。
DataGridRow BillRow = sender as DataGridRow;我将所选行的详细信息放入BillRow (我可以在Visualiser中看到它们),但无法将值放入变量。你能帮我吗??
发布于 2013-01-18 19:06:30
以下解决方案可能会对您有所帮助
public static DataGridCell GetCell(DataGrid dataGrid, int row, int column)
{
DataGridRow rowContainer = GetRow(dataGrid, row);
if (rowContainer != null)
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
// try to get the cell but it may possibly be virtualized
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
if (cell == null)
{
// now try to bring into view and retreive the cell
dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
}
return cell;
}
return null;
}https://stackoverflow.com/questions/14397291
复制相似问题