Row Index of selected row

Hello,

how to get selected row index?

I had tried with this:

int rowIndex = 0;

            if (grid.Table.CurrentRecord != null)
            {
                Record r = grid.Table.CurrentRecord;
                int col = grid.TableControl.CurrentCell.ColIndex;
                rowIndex = grid.TableControl.CurrentCell.RowIndex;
            }

but I get wrong value. Wrong value means if I have 3 rows and if I select last row (3rd) the rowIndex value is 5.

3 Replies

AR Arulpriya Ramalingam Syncfusion Team November 17, 2017 10:33 AM UTC

Hi Josip,   
   
Thanks for using Syncfusion products.   
   
As per the GridGroupingControl architecture, the CurrentCell row index is calculated based on the HeaderRow, AddNewRecordRow and FilterBarRoware added in the grid. Hence, the RowIndex of CurrentCell is varies from the Index of the CurrentRecord in underlying data source. You can retrieve the current cell elements from the DisplayElements collection for that particular current cell row index. Please refer to below KB to retrieve the current cell DisplayElements,   
   
   
Moreover, you can retrieve the record index (i.e. the index in underlying datasource) from the Records collection for the CurrentRecord. Please make use of below code,   
   
Code snippet   
   
if (this.gridGroupingControl1.Table.CurrentRecord != null)   
{   
    Record record = this.gridGroupingControl1.Table.CurrentRecord;   
    int recordIndex = this.gridGroupingControl1.Table.Records.IndexOf(record);   
}   
  
Regards,   
Arulpriya   



JO Josip replied to Arulpriya Ramalingam November 17, 2017 09:12 PM UTC

Hi Josip,   
   
Thanks for using Syncfusion products.   
   
As per the GridGroupingControl architecture, the CurrentCell row index is calculated based on the HeaderRow, AddNewRecordRow and FilterBarRoware added in the grid. Hence, the RowIndex of CurrentCell is varies from the Index of the CurrentRecord in underlying data source. You can retrieve the current cell elements from the DisplayElements collection for that particular current cell row index. Please refer to below KB to retrieve the current cell DisplayElements,   
   
   
Moreover, you can retrieve the record index (i.e. the index in underlying datasource) from the Records collection for the CurrentRecord. Please make use of below code,   
   
Code snippet   
   
if (this.gridGroupingControl1.Table.CurrentRecord != null)   
{   
    Record record = this.gridGroupingControl1.Table.CurrentRecord;   
    int recordIndex = this.gridGroupingControl1.Table.Records.IndexOf(record);   
}   
  
Regards,   
Arulpriya   


Thnx a lot! Works fine.


AR Arulpriya Ramalingam Syncfusion Team November 20, 2017 04:10 AM UTC

Hi   Josip, 
 
Thanks for your update.    
 
We are glad to hear that the provided solution was resolved your scenario.   
 
Please let us know if you have any other queries.    
   
Regards, 
Arulpriya 


Loader.
Up arrow icon