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

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

    Hi there,I am trying to control the current row selection using code only. not by pressing up or down keys.

     

    How can i do this?

    I tried getting the row index but due to the sort by column, the index of the first item is something like 2117.

    Can i get the visual index of a row and change it to the following one or previouse one so the result resembells pressing UP or Down on the keyboard?

     

    Thanks for your help,

    Alon 

    Imported from legacy forums. Posted by Alon (had 1754 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Andre, 

     

    That was exactly what I was missing.

     

     

    Imported from legacy forums. Posted by Alon (had 1886 views)

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