DataGrid 获取某行某列的值
DataGrid gets the value of a row and column
我想获取syncfusion的DataGrid中某个单元格的值
像这样:
<dataGrid:SfDataGrid x:Name="sfDataGrid">
</dataGrid:SfDataGrid>
C#:
Sfdatagrid\[i,j\] is useless.
如何获取此单元格的值。
https://help.syncfusion.com/winui/datagrid/overview 文档
在这个官方文档中,我没有找到如何根据行和列的索引获取这个单元格的值。
我想根据行和列的索引得到这个单元格的值
Column A
Column B
Cell 1
Cell 2
Cell 3
Cell 4
比如我想根据行和列的索引得到这个单元格的值
我应该如何用c#编写代码
你需要根据SfDataGrid中的行列索引获取该单元格的值,可以通过SfDatGrid中的View.GetPropertyAccessProvider.GetValue方法实现。请参考下面的代码片段,
private void OnGetCellValueClicked(object sender, RoutedEventArgs e)
{
// Get the cell value for RowIndex = 5 and ColumnIndex = 2
int rowIndex = 5;
int columnIndex = dataGrid.ResolveToGridVisibleColumnIndex(2);
object record = null;
if (columnIndex < 0)
return;
var provider = this.dataGrid.View.GetPropertyAccessProvider();
var mappingName = dataGrid.Columns[columnIndex].MappingName;
var recordIndex = this.dataGrid.ResolveToRecordIndex(rowIndex);
if (this.dataGrid.View.TopLevelGroup != null)
{
var displayElement = this.dataGrid.View.TopLevelGroup.DisplayElements[recordIndex];
if (displayElement == null)
return;
if (displayElement is RecordEntry)
record = ((RecordEntry)displayElement).Data;
}
else
{
record = this.dataGrid.View.Records[recordIndex].Data;
if (record == null)
return;
}
var cellValue = provider.GetValue(record, mappingName);
//here display the cell value for RowIndex = 5 and ColumnIndex = 2
if (cellValue != null)
txtGetCellValue.Text = cellValue.ToString();
}
我想获取syncfusion的DataGrid中某个单元格的值
像这样:
<dataGrid:SfDataGrid x:Name="sfDataGrid">
</dataGrid:SfDataGrid>
C#:
Sfdatagrid\[i,j\] is useless.
如何获取此单元格的值。
https://help.syncfusion.com/winui/datagrid/overview 文档 在这个官方文档中,我没有找到如何根据行和列的索引获取这个单元格的值。
我想根据行和列的索引得到这个单元格的值
Column A | Column B |
---|---|
Cell 1 | Cell 2 |
Cell 3 | Cell 4 |
比如我想根据行和列的索引得到这个单元格的值
我应该如何用c#编写代码
你需要根据SfDataGrid中的行列索引获取该单元格的值,可以通过SfDatGrid中的View.GetPropertyAccessProvider.GetValue方法实现。请参考下面的代码片段,
private void OnGetCellValueClicked(object sender, RoutedEventArgs e)
{
// Get the cell value for RowIndex = 5 and ColumnIndex = 2
int rowIndex = 5;
int columnIndex = dataGrid.ResolveToGridVisibleColumnIndex(2);
object record = null;
if (columnIndex < 0)
return;
var provider = this.dataGrid.View.GetPropertyAccessProvider();
var mappingName = dataGrid.Columns[columnIndex].MappingName;
var recordIndex = this.dataGrid.ResolveToRecordIndex(rowIndex);
if (this.dataGrid.View.TopLevelGroup != null)
{
var displayElement = this.dataGrid.View.TopLevelGroup.DisplayElements[recordIndex];
if (displayElement == null)
return;
if (displayElement is RecordEntry)
record = ((RecordEntry)displayElement).Data;
}
else
{
record = this.dataGrid.View.Records[recordIndex].Data;
if (record == null)
return;
}
var cellValue = provider.GetValue(record, mappingName);
//here display the cell value for RowIndex = 5 and ColumnIndex = 2
if (cellValue != null)
txtGetCellValue.Text = cellValue.ToString();
}