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 6864971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:58:54+00:00 2026-05-27T02:58:54+00:00

I have the next WPF treeview: <TreeView HorizontalAlignment=Left Margin=6,0,0,32 Name=tvProductos Width=158> <TreeViewItem Header=Securities IsExpanded=True

  • 0

I have the next WPF treeview:

        <TreeView HorizontalAlignment="Left" Margin="6,0,0,32" Name="tvProductos" Width="158">
            <TreeViewItem Header="Securities" IsExpanded="True" FontWeight="Bold">
                <TreeViewItem Header="Country" Name="Country" FontWeight="Normal" />
                <TreeViewItem Header="Currency" Name="Currency" FontWeight="Normal" />
                <TreeViewItem Header="Type" Name="Type" FontWeight="Normal" />
                <TreeViewItem Header="ISIN" Name="ISIN" FontWeight="Normal" />
                <TreeViewItem Header="Description" Name="Description" FontWeight="Normal" />
            </TreeViewItem>
            <TreeViewItem Header="Issuer" IsExpanded="True" FontWeight="Bold">
                <TreeViewItem Header="Name" Name="IssuerName" FontWeight="Normal" />
                <TreeViewItem Header="Type" Name="IssuerType" FontWeight="Normal" />
                <TreeViewItem Header="Market" Name="IssuerMarket" FontWeight="Normal" />
            </TreeViewItem>
        </TreeView>

This structure is fixed. Then I bind low level TreeViewItems using code like this:

        Country.ItemsSource = (from d in db.PAISES
                               join p in db.PRODUCTOS on d.IDPAIS equals p.IDPAIS
                               select d.NOMBREPAIS).Distinct();
        Currency.ItemsSource = (from d in db.DIVISAS
                                join p in db.PRODUCTOS on d.IDDIVISA equals p.IDDIVISA
                                select d.NOMBREDIVISA).Distinct();
        Type.ItemsSource = (from d in db.TIPOSPRODUCTO
                            join p in db.PRODUCTOS on d.IDTIPOPRODUCTO equals p.IDTIPOPRODUCTO
                            select d.NOMBRETIPOPRODUCTO).Distinct();
        ...

The problem is that I need to add one checkbox on each node (low and high level). I have been looking for a solution and the best one is using HierarchicalDataTemplate. But I never found a example with fixed and dynamic nodes at same time. I tried with several examples but I couldn’t solve it.

Can you help me on this?

Thank you in advance.

Kind Regards.

  • 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-05-27T02:58:55+00:00Added an answer on May 27, 2026 at 2:58 am

    The way I’d do it is using a helper class that represents the items that can be checked (some would call it a “view model”):

    public class SelectableItem
    {
        public bool IsSelected { get; set; }
        public string Label { get; set; }
    }
    

    This allows you to specify a DataTemplate for this specific type:

    <TreeView HorizontalAlignment="Left" Margin="6,0,0,32" Name="tvProductos" Width="158">
        <TreeView.Resources>
            <DataTemplate DataType="{x:Type local:SelectableItem}" xmlns:local="clr-namespace:WpfApplication1">
                <StackPanel Orientation="Horizontal">
                    <CheckBox IsChecked="{Binding IsSelected}" />
                    <TextBlock Text="{Binding Label}" />
                </StackPanel>
            </DataTemplate>
        </TreeView.Resources>
        <TreeViewItem Header="Securities" IsExpanded="True" FontWeight="Bold">
            <TreeViewItem Header="Country" Name="Country" FontWeight="Normal" />
            <TreeViewItem Header="Currency" Name="Currency" FontWeight="Normal" />
            <TreeViewItem Header="Type" Name="Type" FontWeight="Normal" />
            <TreeViewItem Header="ISIN" Name="ISIN" FontWeight="Normal" />
            <TreeViewItem Header="Description" Name="Description" FontWeight="Normal" />
        </TreeViewItem>
        <TreeViewItem Header="Issuer" IsExpanded="True" FontWeight="Bold">
            <TreeViewItem Header="Name" Name="IssuerName" FontWeight="Normal" />
            <TreeViewItem Header="Type" Name="IssuerType" FontWeight="Normal" />
            <TreeViewItem Header="Market" Name="IssuerMarket" FontWeight="Normal" />
        </TreeViewItem>
    </TreeView>
    

    All you need to do is modify slightly your data sources:

    Country.ItemsSource = (from d in db.PAISES
                           join p in db.PRODUCTOS on d.IDPAIS equals p.IDPAIS
                           select new SelectableItem { Label = d.NOMBREPAIS }).Distinct();
    

    And that should do the trick.

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

Sidebar

Related Questions

I have the next function: function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName(img); for(var i
I have WPF userControl Library project. In it I have window which has next
I have the next code where I defined a WPF toolkit datagrid control called
I have a control that inherits from TreeView (System.Windows.Controls.TreeView from WPF Framework) and it
I have a WPF window with a TreeView that contains a checkbox at each
I have a WPF application and use datagrids. I have a list of name
I have a WPF form with Next and Prev buttons for navigating to the
I have a WPF form that shows a contact (Name, Address and State). The
I have next tables Order , Transaction , Payment . Class Order has some
I'm going to start of by noting that I have next to no python

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.