Nodes not updated when hierarchy are changed

2 posts, 0 answers
  1. Kenneth
    Kenneth avatar
    27 posts
    Member since:
    Nov 2010

    Posted 24 Apr 2013 Link to this post

    I make a treelistview with an itemssource that contains two List items.

     

    When I push a button, I move the last item in as a child on the first item.

    But to get this to work, I need to:

    radTreeListView.ItemsSource = null;
    radTreeListView.ItemsSource = source;

    This operation takes 600 ms when working with 1.000 rows so it is not desirable.

     

    I have tried to make the List item in to an ObservableCollection but with no luck.

     

    Are there any suggestion to an alternative handling?

    The XAML:

     

    <Grid>
            <telerik:RadTreeListView x:Name="radTreeListView" AutoGenerateColumns="False">
                <telerik:RadTreeListView.ChildTableDefinitions>
                    <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}" />
                </telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:RadTreeListView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name" />
                </telerik:RadTreeListView.Columns>
            </telerik:RadTreeListView          
        </Grid>

    The code behind:
    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                  
                List<Item> itemList = new List<Item>();
                itemList.Add(new Item("Drink"));
                this.radTreeListView.ItemsSource = itemList;
      
                radTreeListView.Loaded += delegate(object sender, RoutedEventArgs e)
                {
                    List<Item> source = ((List<Item>)radTreeListView.ItemsSource);
                    source.First().Children.Add(new Item("Carrot"));
      
                    //This works but takes time when I have 1.000 posts:
                    radTreeListView.ItemsSource = null;
                    radTreeListView.ItemsSource = source;
      
                    //Refresh radTreeListView
                    radTreeListView.Rebind();
                };
            }
        }
      
        public class Item
        {
            public Item(string name)
            {
                this.Name = name;
                this.Children = new List<Item>();
            }
      
            public string Name { get; set; }
      
            public List<Item> Children { get; set; }
        }
  2. Kenneth
    Kenneth avatar
    27 posts
    Member since:
    Nov 2010

    Posted 25 Apr 2013 Link to this post

    I just had to set the child as an observableCollection instead of setting it as a List:

    public ObservableCollection<Item> Children { get; set; }
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top