Home Forums WinForms controls Xceed Grid for WinForms Event for Column based sorting Reply To: Event for Column based sorting

User (Old forums)
Member
Post count: 23064

What happens is that the sorting is done, but the repaint of the grid is delayed until all events have been treated, so the grid repaints only once, and not at every change to the grid.  This increases the performance of the grid, but in your case, since the treatment in your SelectInvoiceDetailsForInvoice() is long, it has the side effect you are observing, that is, the grid is not refresh until after this method.

The recommended workaround is to call this method later, for example in the Application.Idle event handler, after the repaint is done.

e.g.:

   private void gcDeliveryNote_Sorted(object sender, EventArgs e)
    {
        EndEdit();
        Application.Idle += new EventHandler( Application_Idle );
    }

    void Application_Idle( object sender, EventArgs e )
    {
        Application.Idle -= new EventHandler( Application_Idle );
        SelectInvoiceDetailsForInvoice();
    }

However, you could also leave the method call in the Sorted event handler, but call EndInit() and Update() on the grid control before calling it.

e.g.:

   private void gcDeliveryNote_Sorted(object sender, EventArgs e)
    {
        EndEdit();
        gcDeliveryNote.EndInit();
        gcDeliveryNote.Update();
        SelectInvoiceDetailsForInvoice();
    }
 

Note that this is not recommended, because the EndInit() call should match a BeginInit() call, and could result in strange behavior in some cases.  Moreover the UI will be frozen until the event handler returns.  But if you do not want to use the Application.Idle event, it is a possible workaround.

 

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