C# 如何在wpf datagrid中获取DataGridHyperlinkColumn的选定项值
我使用的是一个普通的数据网格列,如 我正在使用 var item=datagrid1.SelectedItem; var a=datagrid1.SelectedCells[0]。Column.GetCellContentitem为TextBlock.TextC# 如何在wpf datagrid中获取DataGridHyperlinkColumn的选定项值,c#,wpf,datagrid,C#,Wpf,Datagrid,我使用的是一个普通的数据网格列,如 我正在使用 var item=datagrid1.SelectedItem; var a=datagrid1.SelectedCells[0]。Column.GetCellContentitem为TextBlock.Text 但是如果我使用的是DataGridTextColumn,它给出的值是;为什么?我怎样才能得到价值 您用什么填充数据网格?我通常使用我创建的这个方法,它从数据上下文而不是网格本身获取值 private Tuple<string,in
但是如果我使用的是DataGridTextColumn,它给出的值是;为什么?我怎样才能得到价值 您用什么填充数据网格?我通常使用我创建的这个方法,它从数据上下文而不是网格本身获取值
private Tuple<string,int,string,int> SelectedCell(System.Windows.Controls.DataGrid dataGrid, int textIndex, int valueIndex)
{
string cellText = null, cellValue = null;
//if the text index is out of bounds, fix it
if (dataGrid.SelectedCells.Count < textIndex)
{
textIndex = dataGrid.SelectedCells.Count - 1;
}
else if (textIndex < 0)
{
textIndex = 0;
}
//if the value index is out of bounds, fix it
if (dataGrid.SelectedCells.Count < valueIndex)
{
valueIndex = dataGrid.SelectedCells.Count - 1;
}
else if (valueIndex < 0)
{
valueIndex = 0;
}
System.Data.DataRowView row = dataGrid.SelectedItem as System.Data.DataRowView;
if(row != null)
{
cellText = row[textIndex].ToString();
cellValue = row[valueIndex].ToString();
}
return new Tuple<string,int,string,int>(cellText,textIndex, cellValue, valueIndex);
}
它获取两个索引列索引的值,然后返回这些值以及原始索引超出范围时这些值的索引