Could I Set TreeListView's Row Properties like this?

5 posts, 1 answers
  1. Yu
    Yu avatar
    18 posts
    Member since:
    Aug 2011

    Posted 06 Dec 2011 Link to this post

    Hi,I'm using RadTreeListView,the default TreeListViewRow's IsExpanded Property is controled by a toggle button,right?
    My question is:
    when the IsSelected property is True,Could I give the IsExpanded property a True Value,too?It means the Row Expanded when I Selected the Row.

    best wishes,
    Sky
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Dec 2011 Link to this post

    Hi Yu,

     You could do this like so:

    private void tlv_SelectionChanged(object sender, SelectionChangeEventArgs e)
           {
               if (e.AddedItems.Count > 0)
               {
                   TreeListViewRow selectedRow = this.tlv.ItemContainerGenerator.ContainerFromItem(e.AddedItems[0]) as TreeListViewRow;
                   if (selectedRow != null)
                   {
                       selectedRow.IsExpanded = true;
                   }
               }

    That way when a row is selected, it will be expanded.

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Yu
    Yu avatar
    18 posts
    Member since:
    Aug 2011

    Posted 09 Dec 2011 Link to this post

    Hello,
    Thanks for your reply,and this works! Thank you very much.But,it only happens when the selection changes,how could it happens when the row is clicked?

    Best Regards,
    Sky
  5. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Dec 2011 Link to this post

    Hello Yu,

    If you want to set the row properties when the row is clicked, then you should handle the click. I would suggest you something like this:

    public MainWindow()
           {...
               this.AddHandler(FrameworkElement.MouseDownEvent, newSystem.Windows.Input.MouseButtonEventHandler(OnMouseDown), true);
           }
        
           private void OnMouseDown(objectsender, MouseButtonEventArgs e)
           {
               var s = e.OriginalSource asFrameworkElement;
               var parentRow = s.ParentOfType<GridViewRow>();
               if(parentRow != null)
               {... }
    }

    I hope that this is what you need.

    Best wishes,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Yu
    Yu avatar
    18 posts
    Member since:
    Aug 2011

    Posted 13 Dec 2011 Link to this post

    Hello,
    It's done! It works well!Thank you very much and best wishes to you and Telerik Team!

    Sky
Back to Top
UI for WPF is Visual Studio 2017 Ready