Home Forums WinForms controls Xceed Grid for WinForms Event for Column based sorting

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

    Hi All,

     Thank you for the support given for my previous posts.

     I need to know whether, there is a event firing when I keeping clicking on the same column (while switching between ASC and DESC)

    Imported from legacy forums. Posted by bdmsoft (had 4099 views)

    User (Old forums)
    Member
    Post count: 23064

    Yes there is one, and it’s called SortDirectionChanged, and it’s on Column.  In the event handler, you can verify the SortDirection property of the sender (the column) to be informed of the direction.

    e..g.:

        private void Form1_Load( object sender, EventArgs e )
        {
          foreach( Column col in gridControl1.Columns )
          {
            col.SortDirectionChanged += new EventHandler( col_SortDirectionChanged );
          }
        }

        void col_SortDirectionChanged( object sender, EventArgs e )
        {
          Column col = sender as Column;
          Debug.WriteLine( col.SortDirection.ToString() );
        }

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

    User (Old forums)
    Member
    Post count: 23064

    hi

    it is working fine, but once we change the sorting column (click on another column other than currently selected column)  it fires multiple events. (sorted direction changed)

     

    Imported from legacy forums. Posted by bdmsoft (had 325 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    What is the event fire at the end of sorting function ? I tried

    void gcDeliveryNote_Sorted(object sender, EventArgs e)

    But once we write something on this slows down the sorting process.

     

    Imported from legacy forums. Posted by bdmsoft (had 544 views)

    User (Old forums)
    Member
    Post count: 23064

    It is normal the SortDirectionChanged event fires more than once, since it is subscribed to on each columns, and when you click on another column, the sorted column is unsorted, and the clicked column becomes sorted.

    For the Sorted event, it is difficult to tell what is the problem since I don’t have your code, and it depends on what you do in it, but handling an event always as the “potential” of slowing things down, since it adds one method to process.  However, since this event is triggered only once, at the end of the sorting process, it should not produce any problem.  Can you provide more details on what you do in it, with a code snippet?

     

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

    User (Old forums)
    Member
    Post count: 23064

    Imagine you have two xceed grids, one at Left and one Right. Once you click on a row of left side it should show some related information on your right grid.

    And both grids need to support sorting too, on Right Hand side grid sorting works well.

    On Left side grid, Say, we are sorting using column 0.

    Expectation : 1. Sort based on first column
                  2. After sorting, it should select first row of left grid
                  3. And it should automatically show related rows on Right Grid.

    So I have coded it like this,

        //Hope this event will fire only after completion of sorting process of Left Grid
       private void gcDeliveryNote_Sorted(object sender, EventArgs e)
        {
            EndEdit();
            //Since it is automatically selecting first row of left grid we can call filling
            //of second grid
            SelectInvoiceDetailsForInvoice();
        }

    Note: I thought at the time of firing above event all the sorting process is over..
        
    But the problem is, Once I add “SelectInvoiceDetailsForInvoice()” as in above code, it will slow up the sorting process of Left Grid. if I comment that it is working good (but it is not listing related rows on right grid)

    Hope my question is now more clear to you.. Awaiting for quick answer.

    – Regards

    Imported from legacy forums. Posted by bdmsoft (had 575 views)

    User (Old forums)
    Member
    Post count: 23064

    What are you doing in the EndEdit() and SelectInvoiceDetailsForInvoice() method calls?

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

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    EndEdit() – is nothing it is setting bool flag, to keep track editing is finished.

    SelectInvoiceDetailsForInvoice() – is the one who is populating Right side grid.

    Note:
    I have observed with break points. It seems that it is firing “gcDeliveryNote_Sorted()” event before ending sort operation.
     

    Imported from legacy forums. Posted by bdmsoft (had 531 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    hi,

    Application.Idle method is working great for me. I can use that, I tried the other method too, I have experienced Freezing issue.

    Thank you

    Imported from legacy forums. Posted by bdmsoft (had 4445 views)

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