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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16856 |

    When using the KB Arrow keys  and the highlight reaches the top row I need to allow a Roll Over to the Last row.

    Conversely when using Down Arrow and it reaches the last Row the selection needs to roll up to the first row.  

    Is this possible ?

    Imported from legacy forums. Posted by Hans (had 1919 views)

    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)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.