Search code examples
devexpressxtragrid

DevExpress XtraGrid MakeRowVisible


EDIT: The problem has something to do with when I am invoking the method. If I wait for the form to be displayed, and invoke the method from a menu on the form itself, it works. But if I set the row to be displayed before the form has finished rendering, it doesn't work. Does the XtraGrid raise an event when it has finished rendering?

I am not having any success with making a specific row in the grid visible using its row handle. I've tried both the MakeRowVisible method of the GridView and also simply setting the ColumnView's FocusedRowHandle property, both of which are supposed to bring the specified row into view.

Note: when focusing a row using the ColumnView.FocusedRowHandle property, the View automatically makes the specified row visible on screen. The MakeRowVisible method is used for this purpose. So, you don't have to use the MakeRowVisible method if you need to focus the target row. Simply assign the desired row handle to the ColumnView.FocusedRowHandle property. http://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsGridGridView_MakeRowVisibletopic

I must be missing something basic. Thanks for the help.

 public void SetVisibleRow(int customerid)
        {

         DevExpress.XtraGrid.Views.Base.ColumnView  vw;
         vw = (DevExpress.XtraGrid.Views.Base.ColumnView) MyGrid.DefaultView;

          for ( int i = 0; i < vw.DataRowCount;  i++)
            {
                 if ((int)vw.GetRowCellValue(i, "custid") == customerid)      
                  {
                    // DevExpress.XtraGrid.Views.Grid.GridView gv;
                    // gv =  (DevExpress.XtraGrid.Views.Grid.GridView) MyGrid.DefaultView;
                    // gv.MakeRowVisible(i,false);

                    vw.FocusedRowHandle = i;
                    break;
                  }
            }

        }

Solution

  • If you are calling your SetVisibleRow method in the form's OnLoad event, make sure to call the grid control's ForceInitialize method first.