- IndexResolver
- Example: You can find the record index from row index using ResolveToRecordIndex method.
- ResolveToRecordIndex(int rowIndex)
- ResolveToRowIndex(int recordIndex)
- ResolveToRowIndex(object recordItem)
- ResolveStartIndexOfGroup(Group group)
- ResolveToGridVisibleColumnIndex(int visibleColumnIndex)
- ResolveStartIndexBasedOnPosition()
- ResolveToScrollColumnIndex(int gridColumnIndex)
- ResolveToStartColumnIndex()
- GetDetailsViewDataGridRowIndex(DetailsViewDataGrid detailsViewDataGrid)
- GetTableSummaryCount(VerticalPosition position)
- GetHeaderIndex()
- IsAddNewIndex(int rowIndex)
- IsTableSummaryIndex(int rowIndex)
- IsFilterRowIndex(int rowIndex)
- Dispose
Contact Support
Helpers in Windows Forms DataGrid (SfDataGrid)
21 Jan 202510 minutes to read
IndexResolver
SfDataGrid has DataGridIndexResolver static class present in Syncfusion.WinForms.DataGrid namespace that has some extension methods used to Resolve from row or column index to record or visible column index and vice versa
.
Example: You can find the record index from row index using ResolveToRecordIndex method.
Prototype Table
ProtoType | Description |
---|---|
ResolveToRecordIndex(int rowIndex) |
Resolves Record index from the RowIndex. When RowIndex does not find any records it returns -1. RecordIndex denotes the index of Record in SfDataGrid.View.Records
|
ResolveToRowIndex(int recordIndex) |
Resolves RowIndex from the record index associated with SfDataGrid.View.Records . When record index is lesser than 0 it returns the -1. |
ResolveToRowIndex(object recordItem) |
Resolves row index from the record associated with SfDataGrid.View.Records . When the given record is not available in the collection it returns -1. |
ResolveStartIndexOfGroup(Group group) |
Resolves the start index of group in DataGrid associated with SfDataGrid.View.TopLevelGroup . When there is no group in DataGrid it returns -1. |
ResolveToGridVisibleColumnIndex(int visibleColumnIndex) |
Resolves the GridColumn index from the visible column index. It excludes the RowHeader and IndentColumn . |
ResolveStartIndexBasedOnPosition() |
Resolves the start index based on position. It includes the stacked header also. By default it returns 0. |
ResolveToScrollColumnIndex(int gridColumnIndex) |
Resolves column index from the Grid column index associated with SfDataGrid.Columns . It includes the IndentColumn and RowHeader also. |
ResolveToStartColumnIndex() | Returns start column index of the VisibleColumn. |
GetDetailsViewDataGridRowIndex(DetailsViewDataGrid detailsViewDataGrid) |
Returns the RowIndex of DetailsViewGrid. You can pass the DetailsViewDataGrid as argument. When the DetailsView is not found it returns the -1. |
GetTableSummaryCount(VerticalPosition position) |
Returns the TableSummary count from VerticalPosition.Position . |
GetHeaderIndex() | Returns the header row index. |
IsAddNewIndex(int rowIndex) |
Decides whether the given row index is AddNewRow index or not. |
IsTableSummaryIndex(int rowIndex) |
Decides whether the given row index is TableSummary index or not. |
IsFilterRowIndex(int rowIndex) |
Decides whether the given row index is FilterRow index or not. |
ResolveToRecordIndex(int rowIndex)
To obtain the record index of a specific row in a SfDataGrid control, use the ResolveToRecordIndex method of the DataGridIndexResolver
class. This method takes an integer parameter representing the row index and returns the corresponding record index.
Here is an example of how you can use this method to get the record index of a row:
int rowIndex = 5;
int recordIndex = this.sfDataGrid1.TableControl.ResolveToRecordIndex(rowIndex);
You can also achieve this by directly accessing the method from DataGridIndexResolver as shown below :
int rowIndex = 5;
int recordIndex = DataGridIndexResolver.ResolveToRecordIndex(this.sfDataGrid1.TableControl, rowIndex);
If the record with the specified row index is unavailable, it will return a value of -1. Otherwise, it will return the record index of the specified rowIndex.
ResolveToRowIndex(int recordIndex)
To obtain the row index of a record in a SfDataGrid control, use the ResolveToRowIndex method of the DataGridIndexResolver
class. This method takes an integer parameter representing the record index and returns the corresponding row index.
Here is an example of how you can use this method to get the row index of a record:
int recordIndex = 2;
int rowIndex = this.sfDataGrid1.TableControl.ResolveToRowIndex(recordIndex);
If the specified record index is less than 0, it will return a value of -1. Otherwise, it will return the row index of the specified recordIndex.
ResolveToRowIndex(object recordItem)
To obtain the row index of a specific record in a SfDataGrid control, use the ResolveToRowIndex method of the DataGridIndexResolver
class. This method takes the record object as a parameter and returns the corresponding row index.
Here is an example of how you can use this method to get the row index of a specific record:
int rowIndex = this.sfDataGrid1.TableControl.ResolveToRowIndex(record);
If the specified record is unavailable, it will return a value of -1. Otherwise, it will return the row index of the specified record.
ResolveStartIndexOfGroup(Group group)
To obtain the start index of a specific group in a SfDataGrid control, use the ResolveStartIndexOfGroup method of the DataGridIndexResolver
class. This method takes a group object as a parameter and returns the corresponding group start index.
Here is an example of how you can use this method to get the start index of a specific group:
var group = this.sfDataGrid1.View.TopLevelGroup.Groups[4];
int groupIndex = this.sfDataGrid1.TableControl.ResolveStartIndexOfGroup(group);
If the specified group is unavailable in the SfDataGrid, it will return a value of -1. Otherwise, it will return the start index of the specified group.
ResolveToGridVisibleColumnIndex(int visibleColumnIndex)
To obtain the GridColumn index for the specified visible column index in a SfDataGrid control, use the ResolveToGridVisibleColumnIndex method of the DataGridIndexResolver
class. This method takes the visible column index as a parameter and returns the corresponding GridColumn index.
Here is an example of how you can use this method to get the GridColumn index of a visible column:
int columnIndex = this.sfDataGrid1.TableControl.ResolveToGridVisibleColumnIndex(visibleColumnIndex);
This method excludes the row header and indent column when determining the GridColumn index. It will return the GridColumn index based on the specified visibleColumnIndex.
ResolveStartIndexBasedOnPosition()
To obtain the starting index of a data row based on the positions of other rows such as the AddNewRow,
FilterRow,
and UnBoundRow,
use the ResolveStartIndexBasedOnPosition method of the DataGridIndexResolver
class.
Here is an example of how you can use this method to get the data row starting index:
int startColumnIndex = this.sfDataGrid1.TableControl.ResolveStartIndexBasedOnPosition();
The method will return an index of the first data row in the SfDataGrid and includes the stacked header row if present when determining the data row starting index. By default, the method returns 0.
ResolveToScrollColumnIndex(int gridColumnIndex)
To obtain the visible column index for the specified GridColumn index in a SfDataGrid control, use the ResolveToScrollColumnIndex method of the DataGridIndexResolver class
. This method takes the GridColumn index as a parameter and returns the corresponding visible column index.
Here is an example of how you can use this method to get the visible column index based on the specific GridColumn index:
int columnIndex = this.sfDataGrid1.TableControl.ResolveToScrollColumnIndex(gridColumnIndex);
This method includes the row header and indent column when determining the visible column index. It will return the visible column index based on the gridColumnIndex.
ResolveToStartColumnIndex()
To obtain the start column index in a SfDataGrid control, use the ResolveToStartColumnIndex method of the DataGridIndexResolver
class.
Here is an example of how you can use this method to get the start column index:
int startColumnIndex = this.sfDataGrid1.TableControl.ResolveToStartColumnIndex();
This method will return an index of the start column index in the SfDataGrid.
GetDetailsViewDataGridRowIndex(DetailsViewDataGrid detailsViewDataGrid)
To obtain the row index of a DetailsViewDataGrid in a SfDataGrid control, use the GetDetailsViewDataGridRowIndex method of the DataGridIndexResolver
class. This method takes the DetailsViewDataGrid as a parameter and returns the corresponding details view row index.
Here is an example of how you can use this method to get the details view row index of a DetailsViewDataGrid:
int detailsViewRowIndex = this.sfDataGrid1.GetDetailsViewDataGridRowIndex(detailsViewDataGrid);
If the specified DetailsViewDataGrid is unavailable in the SfDataGrid, it will return a value of -1. Otherwise, it will return the row index of the DetailsViewDataGrid.
GetTableSummaryCount(VerticalPosition position)
To obtain the total number of table summary rows in a specific position, for example, top or bottom in a SfDataGrid, use the GetTableSummaryCount method of the DataGridIndexResolver
class. This method takes a VerticalPosition
enum value as a parameter and returns the number of table summary rows in the specified position.
Here is an example of how you can use this method to get the total number of table summary rows in the SfDataGrid in the top position:
int tableSummaryCount = this.sfDataGrid1.TableControl.GetTableSummaryCount(VerticalPosition.Top);
This will return the total number of table summary rows in the SfDataGrid. By default, the method returns 0 if the SfDataGrid does not have any table summary row.
GetHeaderIndex()
To obtain the header row index of a SfDataGrid control, use the GetHeaderIndex method of the DataGridIndexResolver
class. This method returns the index of the header row in the SfDataGrid.
Here is an example of how you can use this method to get the header row index in the SfDataGrid:
int headerRowIndex = this.sfDataGrid1.TableControl.GetHeaderIndex();
This will return the index of the header row in the SfDataGrid.
IsAddNewIndex(int rowIndex)
To determine if a specific row index in a SfDataGrid is associated with the AddNewRow,
use the IsAddNewIndex method of the DataGridIndexResolver
class. This method takes the row index as a parameter and returns a boolean value indicating whether the specified row is the AddNewRow.
Here is an example of how you can use this method to determine if a row is the AddNewRow:
bool isAddNewRow = this.sfDataGrid1.IsAddNewRowIndex(rowIndex);
This will return true
if the specified rowIndex is associated with the AddNewRow,
and false
otherwise.
IsTableSummaryIndex(int rowIndex)
To determine if a specific row index in a SfDataGrid is associated with the TableSummaryRow,
use the IsTableSummaryIndex method of the DataGridIndexResolver
class. This method takes the row index as a parameter and returns a boolean value indicating whether the specified row is a TableSummaryRow.
Here is an example of how you can use this method to determine if a row is a TableSummaryRow:
bool isTableSummaryRow = this.sfDataGrid1.TableControl.IsTableSummaryIndex(rowIndex);
This will return true
if the specified rowIndex is associated with the TableSummaryRow,
and false
otherwise.
IsFilterRowIndex(int rowIndex)
To determine if a specific row index in a SfDataGrid is associated with the FilterRow,
use the IsFilterRowIndex method of the DataGridIndexResolver
class. This method takes the row index as a parameter and returns a boolean value indicating whether the specified row is the FilterRow.
Here is an example of how you can use this method to determine if a row is a FilterRow:
bool isFilterRow = this.sfDataGrid1.IsFilterRowIndex(rowIndex);
This will return true
if the specified rowIndex is associated with the FilterRow,
and false
otherwise.
Dispose
The method is associated with relinquishes memory and clears all references associated with SfDataGrid. When you call this method, it releases all the reference for SfDataGrid. So the memory it is occupying using the DataGrid is reclaimed. You have to call SfDataGrid.Dispose
method to release the memory.