Bind To Row's Expanded State

8 posts, 0 answers
  1. Terry Foster
    Terry Foster avatar
    60 posts
    Member since:
    Sep 2009

    Posted 24 Sep 2010 Link to this post

    I need my view model to know, as a parent item, if it's row is expanded or collapsed and, ideally, be able to likewise expand or collapse it's row (without interacting directly with the TreeListView).  Is there a way to do this?

  2. Yavor Georgiev
    Yavor Georgiev avatar
    982 posts

    Posted 27 Sep 2010 Link to this post

    Hi Terry Foster,

     You need to handle the RowLoaded event like so:
    var row = e.Row as TreeListViewRow;
    if (row != null)
      var binding = new Binding("IsExpanded") { Source = row.Item };
      binding.Mode = BindingMode.TwoWay;
      row.SetBinding(TreeListViewRow.IsExpandedProperty, binding);

    This will bind the row's expanded state to the IsExpanded property of your data item.

    Sincerely yours,
    Yavor Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Peter
    Peter avatar
    2 posts
    Member since:
    Aug 2012

    Posted 01 Aug 2012 Link to this post


    I have used you code but getting run-time error:

    Error HRESULT E_FAIL has been returned from a call to a COM component.


       v MS.Internal.XcpImports.CheckHResult(UInt32 hr)
       v MS.Internal.XcpImports.Collection_Clear[T](PresentationFrameworkCollection`1 collection)
       v System.Windows.PresentationFrameworkCollection`1.ClearImpl()
       v System.Windows.PresentationFrameworkCollection`1.Clear()
       v Telerik.Windows.Controls.GridView.GridViewBaseVirtualizingPanel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args)
       v Telerik.Windows.Controls.GridView.GridViewBaseVirtualizingPanel.OnItemsChangedHandler(Object sender, ItemsChangedEventArgs args)
       v Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.OnRefresh()
       v Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.Refresh()
       v Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsChanged(NotifyCollectionChangedEventArgs e)
       v Telerik.Windows.Controls.GridView.BaseItemsControl.OnItemCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       v System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
       v Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       v Telerik.Windows.Data.DataItemCollection.OnCollectionViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       v Telerik.Windows.Data.Listener`2.ReceiveWeakEvent(Object sender, TArgs args)
       v Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
       v System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
       v Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
       v Telerik.Windows.Data.HierarchicalCollectionView.RefreshOnExpandCollapse(IHierarchicalChildCollectionView expandedView)
       v Telerik.Windows.Data.HierarchicalCollectionView.ExpandItem(Object item)
       v Telerik.Windows.Controls.RadTreeListView.ToggleHierarchyItemExpandStateInHierarchyViewFromUI(Object hierarchyItem, Boolean isExpanding)
       v Telerik.Windows.Controls.TreeListView.TreeListViewRow.OnIsExpandedChanged(Boolean oldValue, Boolean newValue)
       v Telerik.Windows.Controls.GridView.GridViewRow.OnIsExpandedChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
       v Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       v System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
       v System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       v System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)
       v System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
       v System.Windows.FrameworkElement.SetBinding(DependencyProperty dp, Binding binding)
       v MyView.ActivityMonitorTreeView_RowLoaded(Object sender, RowLoadedEventArgs e)
       v Telerik.Windows.Controls.GridView.GridViewDataControl.OnRowLoaded(RowLoadedEventArgs e)
       v Telerik.Windows.Controls.GridView.GridViewDataControl.RaiseRowLoaded(GridViewRowItem row)
       v Telerik.Windows.Controls.GridView.GridViewRowItem.MeasureOverride(Size constraint)
       v System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

    I need rows in RadTreeListView to be expanded according property IsExpanded in my ViewModel. I have tried many approaches to get it work but I am getting just strange results (similar like the above).
    Any idea? 

  4. Nick
    Nick avatar
    593 posts

    Posted 06 Aug 2012 Link to this post

    Hello Peter,

    The code that is suggested by my colleague is outdated. Unfortunately the current version of the RadTreeListView does not support binding the IsExpanded property. May I ask you to share what is your final goal so I can suggest an alternative? 

    Looking forward to hearing from you. 

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Peter
    Peter avatar
    2 posts
    Member since:
    Aug 2012

    Posted 06 Aug 2012 Link to this post

    Hi Nik,

    Thanks for your reply. I will try to describe my situation.
    I have RadTreeListView bound to list of ItemViewModel. ItemViewModel represents the viewmodel of entity which is in some state and can have some child entities. ItemViewModel also contains IsExpanded property which is set during initialization as follows:
    if (entity.State == States.RUNNING && entity.Childs.Any())
        IsExpanded = true;
        IsExpanded = false;

    So first time RadTreeListView is loaded I need some rows to be expanded according to their ViewModel IsExpanded property.
    I expected to do this by setting binding between rows IsExpanded property and thier appropriated ViewModel IsExpanded property. Unfortunately this straightforward approach doesnt work. Is there some other way how it can be done?

  6. Nick
    Nick avatar
    593 posts

    Posted 09 Aug 2012 Link to this post

    Hi Terry,

    The best way to achieve the desired behavior would be to use a style selector for the TreeListView rows, so that they are expanded depending on a property in the business object. You can see examples of RowStyleSelectors here.

    Let me know if I can help you further on the matter.

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Mike
    Mike avatar
    17 posts
    Member since:
    Jul 2010

    Posted 07 Jan 2013 Link to this post

    Has there been any updates?  Does the latest TreeListView control support binding IsExpanded property to a property of a custom business object via ContainerBindingsCollection?  Thanks.
  8. Vlad
    Vlad avatar
    11100 posts

    Posted 08 Jan 2013 Link to this post


     I'm afraid that we still cannot offer such solution. 

    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top