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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:56:08+00:00 2026-06-10T04:56:08+00:00

I am looking to implement a treeview inside a combobox. Basically I want it

  • 0

I am looking to implement a treeview inside a combobox. Basically I want it to show as a combobox when collapsed but a treeview inside combo box when expanded. When a user clicks on a node, I want it to show in the collapsed combo box. I have got this working so far.

The problem I am having is that how do I show a default value from c# when this combo box is loaded. Please help guys as I am running out of ideas 🙂

Thanks in advance.

Data Template

    <DataTemplate x:Key="TreeViewExpanded" >

        <StackPanel>
            <TreeView x:Name="DPointTree" Margin="5" ItemsSource="{Binding Datapoint}" 
                              Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ComboBox}}}"
                              >
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Field}">
                        <TextBlock Text="{Binding Name}"/>
                                <HierarchicalDataTemplate.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding}"/>
                                    </DataTemplate>
                                </HierarchicalDataTemplate.ItemTemplate>
                            </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
            </TreeView>
        </StackPanel>
        <DataTemplate.Triggers>
            <DataTrigger Binding = "{Binding Path=SelectedFieldName, Mode=TwoWay}" Value = "">
                <Setter Property = "Visibility"  Value = "Collapsed"/>
            </DataTrigger>
        </DataTemplate.Triggers>
</DataTemplate>

Here is the Xaml

 <ComboBox Name="cmbFieldName" Width="150" Background="White" ItemsSource="{Binding}" SelectedItem="{Binding SelectedFieldName , Mode=TwoWay}" >
            <ComboBox.ItemTemplateSelector>
                <local:TreeViewSelector/>
            </ComboBox.ItemTemplateSelector>
        </ComboBox>

Here is the DataSet passed to this.

Datapoint _datapoint2 = new Datapoint();
        _datapoint2.Name = "Alpha";
        _datapoint2.FieldID.Add("Contains Elements");
        _datapoint2.Field.Add("1 Year");
        _datapoint2.Field.Add("2 Year");
        _datapoint2.Field.Add("3 Year");
  • 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-10T04:56:10+00:00Added an answer on June 10, 2026 at 4:56 am

    Try this:

    private void TreeView_Loaded(object sender, RoutedEventArgs e)
            {
                TreeView areaTreeView = sender as TreeView;
    
                // Expand the treeview
                if (areaTreeView != null)
                {
                    ExpandCollapseTreeNodes(areaTreeView, true);
                }
            }
    
    
    
    public static void ExpandCollapseTreeNodes(ItemsControl parentContainer, bool isExpanded)
            {
                foreach (Object item in parentContainer.Items)
                {
                    TreeViewItem currentContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
                    if (currentContainer != null) // && currentContainer.Items.Count > 0
                    {
                        //expand the item
                        currentContainer.IsExpanded = isExpanded;                    
    
                        //if the item's children are not generated, they must be expanded
                        if (isExpanded && currentContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
                        {
                            //store the event handler in a variable so we can remove it (in the handler itself)
                            EventHandler eh = null;
                            eh = new EventHandler(delegate
                            {
                                //once the children have been generated, expand those children's children then remove the event handler
                                if (currentContainer.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                                {
                                    ExpandCollapseTreeNodes(currentContainer, isExpanded);
                                    currentContainer.ItemContainerGenerator.StatusChanged -= eh;
                                }
                            });
    
                            currentContainer.ItemContainerGenerator.StatusChanged += eh;
                        }
                        //otherwise the children have already been generated, so we can now expand those children
                        else
                        {
                            ExpandCollapseTreeNodes(currentContainer, isExpanded);
                        }
                    }
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to implement a search text box as follows: When user starts
I'm looking to implement a warning if the user attempts to leave the order
Looking to implement VisualSVN but I don't have my own server. I could install
I'm looking to implement a UIPickerView where the user presses spin and the picker
I am looking to implement something in Objective-C for the IOS platform. I want
I'm looking to implement an SMS authentication for one of my projects, basically before
I'm looking to implement a parallax effect on a website. I want to know
I am looking to implement a 1 on 1 user to user web chat
looking to implement google closure with msbuild. i found a few solutions but struggling
I'm looking to implement the new Auto Renewable subscriptions using In App purchase but

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.