This is a migrated thread and some comments may be shown as answers.

Parent-Child relation in treeview

1 Answer 93 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 27 Jan 2012, 03:23 PM

This is a simplified version of my class

public class Item
{
int _id;
 string _name;
Item _parentItem;
ObservableCollection<Item> _childItems;
}

The thing I want to do is to have them in a treeview acording to their relationship. And this is how I did it.

<telerikNavigation:RadTreeView
   ItemsSource="{Binding TreeItems,Converter={StaticResource HierarchyConverter}}"
   ItemTemplate="{StaticResource TreeTemplate}"/>
 
<converter:HierarchyConverter x:Name="HierarchyConverter"/>
<telerik:HierarchicalDataTemplate
   x:Key="TreeTemplate"
    ItemsSource="{Binding Converter={StaticResource HierarchyConverter}}">
          <TextBlock Text="{Binding Name}"/>
</telerik:HierarchicalDataTemplate>

And I also use this converter

public class HierarchyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // We are binding an item
            TreeItem item = value as TreeItem;
            if (item != null)
            {
                return item.Children;
            }
 
            ObservableCollection<TreeItem> items = value as ObservableCollection<TreeItem>;
            if (items != null)
            {
                return items;
            }
            return null;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

I only get the first "level" and see the arrows next to the name but they won't expand so that I don't know if I did everything correct.

Any help?

Edit:

Added this code

<telerik:ContainerBindingCollection x:Key="TreeViewItemContainerBinding">
           <telerik:ContainerBinding PropertyName="IsExpanded" Binding="{Binding Path=IsActive, Mode=TwoWay}"/>
           <telerik:ContainerBinding PropertyName="IsSelected" Binding="{Binding Path=IsActive}"/>
       </telerik:ContainerBindingCollection>

But now everything is expanded and when I click on an item it doesnt look like it's selected... it is just "flashing"



1 Answer, 1 is accepted

Sort by
0
Ivan
Top achievements
Rank 1
answered on 27 Jan 2012, 03:36 PM
Ignore the question...

After I used the code (with the edited part) everything worked fine after I took care that the service which was providing me the data was called only once :)
Tags
TreeView
Asked by
Ivan
Top achievements
Rank 1
Answers by
Ivan
Top achievements
Rank 1
Share this question
or