TreeView and TreeViewItems

    General discussion

  • Hi


    how do i get to the real TreeViewItem when i use bindings?


    Dim item As TreeViewItem = New TreeViewItem()
    Dim dc As MenuDomainContext = New MenuDomainContext()
    Dim res = dc.Load(dc.GetIPPlanMenu2ChildsQuery(DirectCast(lb.SelectedItem, IPPlanMenu2).MenuID), AddressOf PopulateMenu, item)
    item.Header = DirectCast(lb.SelectedItem, IPPlanMenu2).MenuText
    item.ItemsSource = res.Entities

    Private Sub PopulateMenu(ByVal loadOp As System.ServiceModel.DomainServices.Client.LoadOperation)
    Dim item As TreeViewItem = loadOp.UserState

    iterating though item.items - these seems to be of type IPPlanMenu2 eg the metaclass containing the data that was bound... i need to find the items of the treeviewitem class...?


    Wednesday, March 28, 2012 8:03 AM

All replies

  • There is a introduction on how to Iterate Through TreeViewItems for RadControls, you can refer:

    Friday, March 30, 2012 3:37 AM
  • Hi.. Thanks for the sugestion, but i hvent been able to get it to work...

    is there a better way of doing this - this is my senario:

    Database table:
       ID : Integer
      ParentID : Integer


    Then i have a ria service that returns the data:

    GetIPPlanMenu2() As IQueryable(Of IPPlanMenu2)


    This i want to get into treeview linked by ParentID..

    Could someone construct a simple example for me, thanks.

    Thursday, April 19, 2012 4:11 AM
  • Ahh - the problem is.. when the data have been loaded async and i get the event, the treeview havnt generated the treeviewitems yet...

    now back to the box and think.,..

    Friday, April 20, 2012 4:57 AM
  • Ok - reverted back to basic... and it almost works...


    <StackPanel Grid.Column="0" Orientation="Vertical" >
          <sdk:HierarchicalDataTemplate x:Key="MenuChild" >
    <TextBlock FontStyle="Italic" Text="{Binding Path=MenuText}" />
    <sdk:HierarchicalDataTemplate x:Key="MenuParent" ItemsSource="{Binding ParentID}" ItemTemplate="{StaticResource MenuChild}">
    <TextBlock Text="{Binding Path=MenuText}" FontWeight="Bold" />
    <sdk:TreeView Name="tvMenu" ItemTemplate="{StaticResource MenuParent}">

    and from the treeview loaded event it get populated by:

    Dim mdc As MenuDomainContext = New MenuDomainContext()
    tvMenu.ItemsSource = mdc.IPPlanMenu2s

    however, it loads everything into one level - i had hoped it would have been "grouped by" the ID, so how do i do that?

    Monday, April 23, 2012 7:57 AM