Articles in this section
Category / Section

How to get the position of a row in datasource from the current cell's rowIndex in WinForms GridGroupingControl?

2 mins read

Row positions


The current cell’s RowIndex gives the elements displayed in the current row, and by using the element, you can get the record details. When it is a record row, the unsorted position of the element's parent record gives the underlying DataRow position.

//Get the Current Cell.
GridCurrentCell cc = this.gridGroupingControl1.TableControl.CurrentCell;

//Create a table object.
Table table = this.gridGroupingControl1.TableControl.Table;

//Retrieve the element from the curret RowIndex.
Element el = table.DisplayElements[cc.RowIndex];

//Get the elements parent record.
Record r = el.ParentRecord;

//Retrieve the position of the record by using the unsorted table index.
int dataRowPos = table.UnsortedRecords.IndexOf(r);

//Prints the current row positon.
Console.WriteLine("The Positon of the Row=" + dataRowPos);
'Get the Current Cell.
Dim cc As GridCurrentCell = Me.gridGroupingControl1.TableControl.CurrentCell

'Create a table object.
Dim table As Table = Me.gridGroupingControl1.TableControl.Table

'Retrieve the element from the curret RowIndex.
Dim el As Element = table.DisplayElements(cc.RowIndex)

'Get the elements parent record.
Dim r As Record = el.ParentRecord

'Retrieve the position of the record by using the unsorted table index.
Dim dataRowPos As Integer = table.UnsortedRecords.IndexOf(r)

'Prints the current row positon.
Console.WriteLine("The Positon of the Row=" & dataRowPos)

Samples:

C#: GetRowPositionGC-CS.zip

VB: GetRowPositionGC-VB.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied