Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF ListView Grouping
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;
}
Posted 19-Jan-12 19:24pm
Edited 19-Jan-12 21:15pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Solved my self thanks!!! i added a ObservableCollection and thn added to ListCollectionView!!! i am able to achive my task !!! thanks
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 275
1 OriginalGriff 230
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 20 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100