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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:27:27+00:00 2026-05-11T19:27:27+00:00

After you have added Items to the root level of a System.Windows.Controls.TreeView, what is

  • 0

After you have added Items to the “root” level of a System.Windows.Controls.TreeView, what is the proper way to add in “subitems” by name?

System.Windows.Controls.TreeView.Items <– doesn’t seem to have a Find() or [] by name.

UPDATE:
Oh, wait… is it TreeView.FindName() ?

Actually looks like FindName won’t work because it returns an object, not something you can add subitems too.

On a second note:
Is it wrong to use a class like this to load it up with items, since it doesn’t provide a TreeNode like WinForms?

public class TreeItem
{
    public string Name { get; set; }
    public string Text { get; set; }
    public object Tag { get; set; }
}
  • 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-11T19:27:28+00:00Added an answer on May 11, 2026 at 7:27 pm

    You can use .Where ExtensionMethod on the TreeView.Items collection, and then find by whatever you want.

    There isn’t a TreeNode any more in WPF, instead a TreeView has TreeViewItems, ListView has ListViewItems, etc. So the TreeViewItem is what you should be using in these case. (Though you can add anything you like to the TreeView, it’ll wrap it for you.)

    FindName returns an object because it doesn’t know what it’s going to find, you have to cast it to what you expect it to be. But that is the behavior you want to be using. Also, while any elements with a Name are automatically registered if they are created in XAML, that is not the case if you are creating the items in C#/VB and adding them to the UI. You will have to ‘register’ their name in order to be able to access it by FindName().

    Here’s a small example demonstrating the TreeViewItem and accessing TreeView’s elements through FindName:

    TreeView tree = new TreeView() { Name = "tree" };
    uiDockPanel.Children.Add(tree);
    
    var item1 = new TreeViewItem() { Header = "Item 1", Name = "Item1" };
    tree.Items.Add(item1); 
    item1.RegisterName("Item1", item1);
    
    var item2 = new TreeViewItem() { Header = "Item 2", Name = "Item2" };
    tree.Items.Add(item2); 
    item1.RegisterName("Item2", item2);
    
    var item3 = new TreeViewItem() { Header = "Item 3", Name = "Item3" ;
    tree.Items.Add(item3);          
    item1.RegisterName("Item3", item3);
    
    var i2 = tree.FindName("Item2") as TreeViewItem;
    var subitem = new TreeViewItem() { Header = "SubItem 1"};
    i2.Items.Add(subitem);  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this XML: <root> <tab name=Detail> <section name=mysection> <items level=1> <Idx_name>9</Idx_name> <Type>mytype</Type> <item
Why the following code returns empty after I have added several items in it?
After installing RBEnv and rebuilding my ROR project, I now seem to have added
Have you ever added unit tests, after the fact, to legacy code? How complicated
I have created a cube that worked fine when deploying. After a added another
I have the following tables: users userId|name items itemId|userId|description What I want to achieve:
I am workin on tab Controls in WPF. I have added a set of
I have a ASP DropDownList with items added to it. All what I want
I'm trying to add paging functionality to a search items page. so I have
After I have created a serious bunch of classes (with initialize methods), 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.