wpf +分组listview [英] wpf + grouping listview

查看:85
本文介绍了wpf +分组listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
下面是我目前用于列表视图分组的代码.我能够对记录进行分组,但是当用户单击按钮(AddNewCluster)以创建具有记录集的新组时,我无法与旧记录连接.列表视图将使用新的组和记录进行更新.但是我需要向用户显示旧的和新添加的组和记录.

Hello,
Below is the code currently i am using for grouping in listview. I am able to group records, but when user clicks on the button(AddNewCluster) to create new group with set of records i am unable to concatenate with the old records. The listview gets updated with the new group and records. But i need to show the user both the old and newly added group and records.

ListCollectionView collectionView; 
 
public Window1() 
{
InitializeComponent();
 
var clusters = new[] 
{
 
new Cluster { Name = "Front end" }, 
 
new Cluster { Name = "Middle end" }, 
 
new Cluster { Name = "Back end" }, 
};
collectionView =
new ListCollectionView(new[] 
{
 
new Server { Cluster = clusters[0], Name = "webshop1" }, 
 
new Server { Cluster = clusters[0], Name = "webshop2" }, 
 
new Server { Cluster = clusters[0], Name = "webshop3" }, 
 
new Server { Cluster = clusters[0], Name = "webshop4" }, 
 
new Server { Cluster = clusters[0], Name = "webshop5" }, 
 
new Server { Cluster = clusters[0], Name = "webshop6" }, 
 
new Server { Cluster = clusters[2], Name = "sql1" }, 
 
new Server { Cluster = clusters[2], Name = "sql2" }, 
});
 
var groupDescription = new PropertyGroupDescription("Cluster.Name"); 
 
// this foreach must at least add clusters that can't be  
 
// derived from items - i.e. groups with no items in them  
 
foreach (var cluster in clusters) 
groupDescription.GroupNames.Add(cluster.Name);
collectionView.GroupDescriptions.Add(groupDescription);
ServersList.ItemsSource = collectionView;
Clusters = groupDescription.GroupNames;
}
 
readonly ObservableCollection<object> Clusters; 
 
void AddNewCluster_Click(object sender, RoutedEventArgs e) 
{
Clusters.Add(NewClusterName.Text);
 
var clusters = new[] 
{
 
new Cluster { Name = NewClusterName.Text }, 
};
 
collectionView =
new ListCollectionView(new[] 
{
 
new Server { Name = "new server data" }, 
});
 
var groupDescription = new PropertyGroupDescription("Cluster.Name"); 
 
// this foreach must at least add clusters that can't be 
 
// derived from items - i.e. groups with no items in them 
 
foreach (var cluster in clusters) 
groupDescription.GroupNames.Add(cluster.Name);
collectionView.GroupDescriptions.Add(groupDescription);
ServersList.ItemsSource = collectionView;
}

推荐答案

解决了我的自我感谢!!!我添加了一个ObservableCollection,然后将其添加到ListCollectionView中!!!我能够实现我的任务!谢谢
Solved my self thanks!!! i added a ObservableCollection and thn added to ListCollectionView!!! i am able to achive my task !!! thanks


这篇关于wpf +分组listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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