How to group data of LIstview in WPF?

How to group data of Listview when data are bind from SQL Database

I used Collection View Source for that but it is not working

My Code lines are mentioned below :

    CollectionViewSource viewSource = new CollectionViewSource { Source = ds };
    viewSource.GroupDescriptions.Add(new PropertyGroupDescription("RequestID"));
    ListView1.ItemsSource = viewSource.View;

but it not working properly , even data are not show in listview when Listview Item Source is bind with Collection View Source

Please help me out. Thanks a lot.

Upvotes: 0

Views: 1829

Answers (1)

blindmeis
blindmeis

Reputation: 22445

you can try the following

ICollectionView view = CollectionViewSource.GetDefaultView(ds);
view.GroupDescriptions.Add(new PropertyGroupDescription("RequestID"));
listview1.ItemsSource = view;

dont forget to set a grouping template. btw here is a related question with an complete anwser.

Upvotes: 2

Related Questions