从CollectionViewSource中删除GroupDescription [英] Removing GroupDescription from CollectionViewSource
问题描述
大家好,
我正在尝试使用绑定到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 useRemoveAt
:
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屋!