Grouping Comparer Only Works Correctly When Initialized

Hi there,

I'm using the grouping feature and using my custom grouping comparer.

I have a situation where I have to clear my data source and add new items to it.

The expected behavior is to group and sort my groups according to my custom logic

What happens is the groups are created and sorted successfully only for the first set of items and whenever I update the data source the comparer doesn't work as expected.


My Notes:

While debugging I noticed that the Items property in the GroupResult object always = null when data source is updated.


I replicated the logic I have but in a more simpler approach so we can isolate the issue easily


Please update me ASAP


Thanks very much


Attachment: ListGrouping_baf78285.zip

1 Reply

LN Lakshmi Natarajan Syncfusion Team December 20, 2021 02:37 PM UTC

Hi Mahmoud, 
 
The reported scenario occurs because you are adding items in a loop, causing the GroupComparer to be called for each addition. And the list only has one item for the first added item, with no other items to compare. As a result, we recommend that you call the DataSource.BeginInit and DataSource.EndInit methods when adding the items, which will allow you to process the data once all of the items have been added. 
 
Please refer to the following code snippets for more reference, 
 
void Button_Clicked(System.Object sender, System.EventArgs e) 
{ 
    DataSource.Clear(); 
 
    listView.DataSource.BeginInit(); 
    if (isClicked) 
        foreach (var item in set1) 
        { 
            DataSource.Add(item); 
        } 
 
    else 
        foreach (var item in set2) 
        { 
            DataSource.Add(item); 
        } 
 
    listView.DataSource.EndInit(); 
    isClicked = !isClicked; 
} 
 
You can also refer to our user guidance document regarding the same in the following link, 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon