C# 从WPF中的DataGridRow获取列值
我正在创建一个WPF应用程序,当用户单击DataGrid的一行时,我需要获取一个列值,并使用该值从数据库中获取数据 我能够找到DataGridRow,但无法获取列值。这是我的密码C# 从WPF中的DataGridRow获取列值,c#,wpf,wpf-controls,wpfdatagrid,C#,Wpf,Wpf Controls,Wpfdatagrid,我正在创建一个WPF应用程序,当用户单击DataGrid的一行时,我需要获取一个列值,并使用该值从数据库中获取数据 我能够找到DataGridRow,但无法获取列值。这是我的密码 DataGridRow BillRow = sender as DataGridRow; 我将所选行的详细信息输入BillRow(我可以在Visualiser中看到它们),但无法将值输入变量。你能帮我吗 以下解决方案可能对您有所帮助 public static DataGridCell GetCell(DataGr
DataGridRow BillRow = sender as DataGridRow;
我将所选行的详细信息输入BillRow(我可以在Visualiser中看到它们),但无法将值输入变量。你能帮我吗 以下解决方案可能对您有所帮助
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;
}
公共静态DataGridCell GetCell(DataGrid DataGrid,int行,int列)
{
DataGridRow rowContainer=GetRow(dataGrid,row);
if(rowContainer!=null)
{
DataGridCellsPresenter=GetVisualChild(行容器);
//尝试获取该单元,但它可能已虚拟化
DataGridCell=(DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(列);
if(单元格==null)
{
//现在试着把手机放在视野里,然后拿回手机
ScrollIntoView(rowContainer,dataGrid.Columns[column]);
单元格=(DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(列);
}
返回单元;
}
返回null;
}
>您能帮我吗?数据绑定将帮助您。:)在WPF中没有它很难工作: