从CollectionViewSource中删除GroupDescription [英] Removing GroupDescription from CollectionViewSource

查看:97
本文介绍了从CollectionViewSource中删除GroupDescription的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试使用绑定到CollectionviewSource的数据网格,我可以按如下方式对项目进行分组:

 ICollectionView CV = CollectionViewSources.GetDefaultView(datagridItems.itemssource); 
CV.GroupDescriptions.Add( new PropertyGroupDescription( 等级));





事情是我不知道如何使用CV删除组.GroupDesciptions.Remove()。



谢谢你。

解决方案

你要么找到了要删除的项目:

  var  itemToRemove = CV.GroupDescriptions 
.OfType< PropertyGroupDescription> ;()
.FirstOrDefault(pgd = > pgd.PropertyName == 等级);

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



或查找其索引并使用 RemoveAt

< pre lang =cs> for int index = 0 ; index < CV.GroupDescriptions.Count; index ++)
{
var pgd = CV.GroupDescriptions [index] as PropertyGroupDescription;
if (pgd!= null && pgd.PropertyName == 等级
{
CV.GroupDescriptions.RemoveAt(index);
break ;
}
}


Hello everyone,

I am trying to use a datagrid that's bound to a CollectionviewSource, I could group items as follows :

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.

解决方案

You either need to find the item you want to remove:

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:

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;
    }
}


这篇关于从CollectionViewSource中删除GroupDescription的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆