We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Moving up/down with keyboard and getting current row index


How to get current row index while moving up/down with navigation keys?

I had tried on this way but I get wrong values. It starts row index from not 0.

this.gridAnalitika.TableOptions.AllowSelection = GridSelectionFlags.Row | GridSelectionFlags.AlphaBlend;

private void gridAnalitika_TableControlCurrentCellKeyDown(object sender, GridTableControlKeyEventArgs e)

            GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.TableControl.CurrentCell.RowIndex, e.TableControl.CurrentCell.ColIndex);
            Record record = style.TableCellIdentity.DisplayElement.GetRecord();

            Console.WriteLine("Current row index: " + record.GetRowIndex());

My grid contains headers, filter columns and then data rows.


1 Reply

SR Sabaridass Ramamoorthy Syncfusion Team April 29, 2019 10:49 AM UTC

Hi Josip, 
Thanks for contacting Syncfusion Support. 
As per the default behavior of GridGroupingControl, 0 is the index of GroupDropArea and 1 is the index of header rows. All the data rows have been started from index 2 based on the index of data row view in data table. If you are still would like get the row index starting from 0 means, you need to compute the row index based on the index of 0th row view of data table. We have prepared a simple sample to achieve your requirement and it can be downloaded from below location. 
Refer to the below code example. 
private void GridGroupingControl1_TableControlCurrentCellKeyUp(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlKeyEventArgs e) 
            GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.TableControl.CurrentCell.RowIndex, e.TableControl.CurrentCell.ColIndex); 
            Record record = style.TableCellIdentity.DisplayElement.GetRecord(); 
            int startIndex = this.gridGroupingControl1.Table.Records[0].GetRowIndex(); 
            int actualIndex = record.GetRowIndex() - startIndex; 
            Console.WriteLine("Current row index: " + actualIndex); 
If the above solution doesn’t meet your actual requirement, kindly provide the detailed information about your requirement. So that it would be helpful for us to proceed further. 
Sabaridass R 

Live Chat Icon For mobile
Up arrow icon