Cell selection, just like in Excel, can be enabled by setting SfDataGrid.SelectionUnit as Cell or Any. While selecting cells using cell selection, you can access the selected cells details using the SfDataGrid.GetSelectedCells method. It returns the collection of GridCellInfo.
Here, SfDataGrid is defined with cell selection by setting SelectionUnit as Cell.
The following code example explains how you can get the selected cells’ information using SfDataGrid.GetSelectedCells method.
The GridCellInfo class contains the following properties:
RowData- Gets or sets record information of the row.
RowIndex- Gets row index of the selected cell.
Column- Gets or sets the column of the selected cell.
IsDataRowCell- Gets a value indicating whether the selected cell is a data row cell.
IsAddNewRow- Gets a value indicating whether the selected cell is in AddNewRow.
You can use the following helpers to extract information from GridCellInfo:
GridIndexResolver.ResolveToRowIndex- You can use this method to get RowIndex from the Record, GridCellInfo.RowData.
GridIndexResolver.ResolveToRecordIndex- You can use this method to get Record index from the RowIndex, GridCellInfo.RowIndex.
GridIndexResolver.ResolveToGridVisibleColumnIndex- You can use this method to get the visiblecolumn index from the GridColumn index.
SfDataGrid.View.GetPropertyAccessProvider- This method returns IPropertyAccessProvider, that is used to reflect values by passing value and property name.
Refer the following screenshot to get the information of selected cell value.
|Article ID:||Published Date:||Last Revised Date:||Platform:||Control:||.NET Framework:|
or the page will be automatically redirected to sign-in page in 10 seconds.