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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:38:06+00:00 2026-05-18T07:38:06+00:00

I am trying to create Below parent child structur using WPF tree. Tree ->Parent

  • 0

I am trying to create Below parent child structur using WPF tree.

Tree

 ->Parent

    ->Child

      ->Grand Child.

I have written the below code which is not able to insert for child. Please help me to fix this.

<Window x:Class="NewTree_DynamicNode.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TreeView Name="treeFileSystem" TreeViewItem.Expanded="treeFileSystem_Expanded_1">
            <TreeViewItem Header="Categories" x:Name="_ImageTree" Tag="hi" 
                  x:FieldModifier="private">
                <TreeViewItem TextBlock.FontStyle="Italic" 
                    Header="Loading..." Name="treeFileSystem2"/>
            </TreeViewItem>
        </TreeView>
    </Grid>
</Window>




private void treeFileSystem_Expanded_1(object sender, RoutedEventArgs e)
        {
            this._ImageTree = (TreeViewItem)e.OriginalSource;
            this._ImageTree.Items.Clear();

            try
            {
                for(int i=0 ; i<2; i++)  
                {
                   TreeViewItem temp = new TreeViewItem();
                   TreeViewItem temp1 = new TreeViewItem();
                    temp.Header = "Parent";
                    temp1.Header = "Child";
                    temp.Items.Add(temp1);                
                    this._ImageTree.Items.Add(temp);                      
                }
            }
            catch
            {
                  /////
            }
        }
  • 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-18T07:38:06+00:00Added an answer on May 18, 2026 at 7:38 am

    Your problem is that every time you expand a node, the child node for the node you expand is always ‘Parent‘

    Im not sure exactly what you are trying to achieve but heres some code:

    TreeViewItem temp = new TreeViewItem();
    temp.Header = "Child";
    temp.Items.Add(null);
    this._ImageTree.Items.Add(temp);
    

    EDIT – this is for specific names in hierarchy

    TreeViewItem temp = new TreeViewItem();
    var header = string.Empty;
    switch (_ImageTree.Header.ToString())
    {
        case "Categories":
            header = "Parent";
            break;
        case "Parent":
            header = "Child";
            break;
        case "Child":
            header = "GrandChild";
            break;
        default:
            header = "Child of " + _ImageTree.Header;
            break;
    }
    temp.Header = header;
    temp.Items.Add(null);
    this._ImageTree.Items.Add(temp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a custom drop down and using the code below it
I am trying to create a table which captures parent child relationships, like a
I am trying to create an add-in by using the article below http://blogs.microsoft.co.il/blogs/shair/archive/2008/07/28/how-to-create-sql-server-management-studio-addin.aspx I
InSymfony (Doctrine) I am trying to create a public function with the code below.
I have the below configuration where I'm trying to create a test C function
I'm trying to create a pinterest pin it button. Below is the code: <a
I am trying to create a new db called testDB2, below is my code.
I am trying to create a treeview dynamically using c# and asp.net. I have
I have been trying to create a red black tree that only implements an
I have a subclass named child which inherits a class named parent. I am

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.