Home Forums WinForms controls Xceed Grid for WinForms Row selection using Arrow keys Reply To: Row selection using Arrow keys

User (Old forums)
Member
Post count: 23064

This is not really possible.  The problem is that the anchoring system for multiple selection will react by removing all non-consecutive rows from the selection, thus having only the top rows selected for example, and no rows selected at the bottom.

The only workaround would be to set the SelectionMode to MultiSimple.  However, the Shift-Selection would not work, and the space bar would be needed to select the row, if the grid is read only.

In any case, here is a code snippet that does not address all situations, but which you can use as a starting point :

    private void Form1_Load( object sender, EventArgs e )
    {
      gridControl1.DataRowTemplate.KeyUp += new KeyEventHandler( DataRowTemplate_KeyUp );
    }

    private bool lastRow = false;

    void DataRowTemplate_KeyUp( object sender, KeyEventArgs e )
    {
      Xceed.Grid.DataRow row = sender as Xceed.Grid.DataRow;

      if( e.KeyCode == Keys.Down && lastRow )
      {
        gridControl1.CurrentRow = gridControl1.DataRows[ 0 ];
        gridControl1.SelectedRows.Add( gridControl1.DataRows[ 0 ] );
        gridControl1.CurrentRow.BringIntoView();
        lastRow = false;
      }
      else if( row == gridControl1.DataRows[ gridControl1.DataRows.Count – 1 ] )
      {
        lastRow = true;
      }
    }

Imported from legacy forums. Posted by André (had 1913 views)