Home Forums WinForms controls Xceed Grid for WinForms How to determine the Index of the Row at which the cursor is located on Xceed grid for .Net Reply To: How to determine the Index of the Row at which the cursor is located on Xceed grid for .Net

User (Old forums)
Member
Post count: 23064

You can use the CurrentRowChanged event, and find the index in the event handle.

e.g.:

    private void Form1_Load( object sender, EventArgs e )
    {

      gridControl1.CurrentRowChanged += new EventHandler( gridControl1_CurrentRowChanged );
    }

    void gridControl1_CurrentRowChanged( object sender, EventArgs e )
    {
      Xceed.Grid.DataRow row = gridControl1.CurrentRow as Xceed.Grid.DataRow;
      //If the row is null, it means the current row is not a data row, but another row like a group header row.
      if( row != null )
      {
        //This will give the index of the row in the GridControl.DataRows collection.
        Debug.WriteLine( row.Index.ToString() );
        //Or this will give the index of the row in the sorted rows collection (if the grid is sorted or grouped).
        Debug.WriteLine( gridControl1.GetSortedDataRows( true ).IndexOf( row ).ToString() );
      }
    }

 

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