Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How to bind TreeView with nested object without using HierarchicalDatatemplate

How to bind TreeView with nested object without using HierarchicalDatatemplate

Scheduled Pinned Locked Moved WPF
csharptutorialwpflinqquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael Sync
    wrote on last edited by
    #1

    Hello All, Is there any way to bind TreeView with nested object without using HierarchicalDatatemplate? For example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { /// /// Interaction logic for Window1.xaml /// public partial class Window1 : Window { public Window1() { InitializeComponent(); List _family = new List(); Person mom = new Person() { Name = "Hteik Tin May" }; mom.Children.Add(new Person() { Name = "Michael Sync" }); mom.Children.Add(new Person() { Name = "Shwesin Sync" }); mom.Children.Add(new Person() { Name = "Aye Nyein Thu" }); mom.Children.Add(new Person() { Name = "Kyaw Zin Thu" }); _family.Add(mom); familyTreeView.ItemsSource = _family; familyTreeView.DisplayMemberPath = "Name"; } } public class Person { readonly List _children = new List(); public IList Children { get { return _children; } } public string Name { get; set; } } } It's not working without HierarchicalDatatemplate. Any idea? Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

    L 1 Reply Last reply
    0
    • M Michael Sync

      Hello All, Is there any way to bind TreeView with nested object without using HierarchicalDatatemplate? For example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { /// /// Interaction logic for Window1.xaml /// public partial class Window1 : Window { public Window1() { InitializeComponent(); List _family = new List(); Person mom = new Person() { Name = "Hteik Tin May" }; mom.Children.Add(new Person() { Name = "Michael Sync" }); mom.Children.Add(new Person() { Name = "Shwesin Sync" }); mom.Children.Add(new Person() { Name = "Aye Nyein Thu" }); mom.Children.Add(new Person() { Name = "Kyaw Zin Thu" }); _family.Add(mom); familyTreeView.ItemsSource = _family; familyTreeView.DisplayMemberPath = "Name"; } } public class Person { readonly List _children = new List(); public IList Children { get { return _children; } } public string Name { get; set; } } } It's not working without HierarchicalDatatemplate. Any idea? Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Any specific reason you don't want to use this HierarchicalDataTemplate? You can always add TreeViewItems manually.

      Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | XAML Power Toys Home Page

      Just a grain of sand on the worlds beaches.

      M 1 Reply Last reply
      0
      • L Lost User

        Any specific reason you don't want to use this HierarchicalDataTemplate? You can always add TreeViewItems manually.

        Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | XAML Power Toys Home Page

        Just a grain of sand on the worlds beaches.

        M Offline
        M Offline
        Michael Sync
        wrote on last edited by
        #3

        I want to depend on the structure of my object. not Hierachical DataTemplate which is static. or Am I missing something? What should I do if I want to change the level of treeview? For example: 2 level Hierachical structure to 5 level Hierachical 2 level Hierachical structure -111 ---22222 ---22222 -333 ---44444 ---44444 5 level Hierachical structure -111 ---22222 --------333333333333 -------------44444444444 -------------------------55555 ---22222 -333 ---44444 ---44444

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

        L 1 Reply Last reply
        0
        • M Michael Sync

          I want to depend on the structure of my object. not Hierachical DataTemplate which is static. or Am I missing something? What should I do if I want to change the level of treeview? For example: 2 level Hierachical structure to 5 level Hierachical 2 level Hierachical structure -111 ---22222 ---22222 -333 ---44444 ---44444 5 level Hierachical structure -111 ---22222 --------333333333333 -------------44444444444 -------------------------55555 ---22222 -333 ---44444 ---44444

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Michael, Please check out my blg entry here. http://karlshifflett.wordpress.com/2008/02/03/wpf-sample-series-databound-hierarchicaldatatemplate-menu-sample/[^] It covers this scenario in detail.

          Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | XAML Power Toys Home Page

          Just a grain of sand on the worlds beaches.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups