Moving up/down with keyboard and getting current row index

Hi

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.

Thanks!

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. 
 
#Form1.cs 
 
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. 
 
Regards, 
Sabaridass R 


Loader.
Up arrow icon