Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I am trying to use a datagrid that's bound to a CollectionviewSource, I could group items as follows :
C#
ICollectionView CV = CollectionViewSources.GetDefaultView(datagridItems.itemssource);
CV.GroupDescriptions.Add(new PropertyGroupDescription("Level"));


the thing is I didn't know how to remove the group using the CV.GroupDesciptions.Remove().

Thank you previously.
Posted

1 solution

You either need to find the item you want to remove:
C#
var itemToRemove = CV.GroupDescriptions
    .OfType<PropertyGroupDescription>()
    .FirstOrDefault(pgd => pgd.PropertyName == "Level");

if (itemToRemove != null) 
{
    CV.GroupDescriptions.Remove(itemToRemove);
}

or find its index and use RemoveAt:
C#
for (int index = 0; index < CV.GroupDescriptions.Count; index++)
{
    var pgd = CV.GroupDescriptions[index] as PropertyGroupDescription;
    if (pgd != null && pgd.PropertyName == "Level")
    {
        CV.GroupDescriptions.RemoveAt(index);
        break;
    }
}
 
Share this answer
 
Comments
Ailane Twofik Muhammed 12-May-15 10:07am    
Thank you very much Sir, worked Perfectly, my mistake that I used the FirstOrDefault() with the lambda expression without the TypeOf<>() so I couldn't get the propertyName.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900