Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8393939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:56:08+00:00 2026-06-09T19:56:08+00:00

I am trying to mimic the msn messenger contactlist treeview display. I have a

  • 0

I am trying to mimic the msn messenger contactlist treeview display.
I have a Contact object which has a Groups property that returns an array msngroups that the Contact belongs, this meaning say I have something as per bellow

Class Contact
{
    string Name;
    string[] Groups {get;set;}
 }

 ObservableCollection<Contact> ContactList;

So a contact can be in mutiple groups, is that possible to use CollectionViewSource to generate the correct view to feed a wpf TreeView?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:56:10+00:00Added an answer on June 9, 2026 at 7:56 pm

    The grouping would work when you flatten this hierarchy i.e. “Contact having Groups” into “Repeated Contacts having each single group” …

    e.g.

    If you have 4 items with groups like …

    Dog { mammal, quadruped }
    Man { mammal, biped }
    PrayingMantis { insect, quadruped }
    Pegion { bird, biped }
    

    Then you new flat list should be like this…

    <mammal, Dog>
    <mammal, Man>
    <bird, Pigeon> 
    <insect, PrayingMantis>
    <biped, Man>
    <biped, Pigeon>
    <quadruped, Dog>
    <quadruped, PrayingMantis>
    

    So after applyin grouping on the Keys above it should be

    mammal { Dog, Man }
    bird { Pigeon }
    insect { PrayingMantis }
    biped { Man,  Pigeon }
    quadruped { Dog, PrayingMantis }
    

    C# Code:

    //Flatten the groups into a KeyValuePair<string, Contacts> list using LINQ.
    var flatGroups 
        = listGroups.SelectMany(
            ctc => ctc.Groups.Select(
                 grp => new KeyValuePair<string, Contact>(grp, ctc))).ToList();          
    
    //Apply CollectionViewSource group on the `Key`.
    var collectionVwSrc = new CollectionViewSource();
    collectionVwSrc.Source = flatGroups;
    collectionVwSrc.GroupDescriptions.Add(new PropertyGroupDescription("Key"));
    
    //Apply groups as itemssource to the TreeView.
    MyGroupsTree.ItemsSource = collectionVwSrc.View.Groups; 
    

    XAML

        <TreeView x:Name="MyGroupsTree">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Items}">
                    <!--GroupItem.Name--> 
                    <TextBlock Text="{Binding Path=Name}" 
                               FontWeight="Bold"/>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <!--Contact.Name-->
                            <TextBlock Text="{Binding Value.Name}"/>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    

    Let me know if this helps…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have javascript code that i am trying to mimic in an android application:
My Zend Framework 2 application has a route definition that's trying to mimic the
I am trying to mimic something that I have seen a few different times.
I'm trying to mimic the vote-up vote-down system that is on this website. Is
I'm trying to mimic visual style of TabHost widget. The problem is that the
I'm trying to mimic IP camera that use MJPEG. At this moment to receive
Here is a graphical output that I'm trying to mimic. I want a series
So, I'm trying to mimic something like Pandora's menu: Where you have the choice
I'm trying to mimic apple's navbar style, specially the CSS3 expanding searchfield. It uses
I am trying to mimic std::map<string, std::list<string> > in VBA (this case is very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.