Home Forums WinForms controls Xceed Grid for WinForms scrolling the rows up and down with through code only (no keyboard) Reply To: scrolling the rows up and down with through code only (no keyboard)

User (Old forums)
Member
Post count: 23064

You need to get the sorted DataRows collection to get the sorted index.  Use the GetSortedDataRows() method on the GridControl to obtain it.

Here is a code snippet showing one way of doing this.  Let’s say you have a button with which you want to navigate down the rows and that you are already sorted on one column from the start :

    private ReadOnlyDataRowList sortedList;

    private void Form1_Load( object sender, EventArgs e )
    {
      gridControl1.SortedColumns.Add( “Country” );
      sortedList = gridControl1.GetSortedDataRows( true );
    }

    private void button1_Click( object sender, EventArgs e )
    {
      Xceed.Grid.DataRow row = gridControl1.CurrentRow as Xceed.Grid.DataRow;
      if( row != null )
      {
        int index = sortedList.IndexOf( row );
        if( index < sortedList.Count – 1 )
        {
          gridControl1.CurrentRow = sortedList[ index + 1 ];
          gridControl1.SelectedRows.Clear();
          gridControl1.SelectedRows.Add( gridControl1.CurrentRow );
          gridControl1.CurrentRow.BringIntoView();
        }
      }
      gridControl1.Focus();
    }

 

 

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