Collapsed Groups lose Collapse on Refresh?

9 posts, 1 answers
  1. Andrew
    Andrew avatar
    28 posts
    Member since:
    Mar 2013

    Posted 04 Apr 2013 Link to this post

    I have an application that dynamically hides/shows properties based on customization.  I'm relying on groups to categorize everything.  When I refresh the control, by making a property visible/hidden or adding a property, all the groups I have collapsed reset expanded.  Is this a bug?  Can I also set group collapsed/expanded from code?

    Thanks!

    (Image attached: all that should change is in the yellow highlights.  I click a checkbox and add new fields.  In the lower image, all the groups suddenly expand when the form is refreshed.
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 05 Apr 2013 Link to this post

    Hello,

    Indeed the groups expand/collapse state is not preserved when you change a property's visibility or you add a new property. This would be the expected behavior though as the entire view is recreated in those cases. I am afraid that this behavior cannot be changed at the moment.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Andrew
    Andrew avatar
    28 posts
    Member since:
    Mar 2013

    Posted 05 Apr 2013 Link to this post

    Can the expand/collapse state of a group be accessed via code so I can save the state manually?  Is this/can this be a planned fix in future releases?
  5. Andrew
    Andrew avatar
    28 posts
    Member since:
    Mar 2013

    Posted 05 Apr 2013 Link to this post

    In addition to preserving the group expand/contract, it would be necessary to preserve the selected control for tabbing purposes.  I think not having these preserve features makes this control unusable for quick, customizable/updatable data-entry.  Which is a shame, because otherwise, I thought it was the solution I needed.
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Apr 2013 Link to this post

    Hello,

    You can find the groups with expanded state using the following approach:

    radPropertyGrid.ChildrenOfType<RadToggleButton>().Where(s => s.Name == "expandCollapseButton" && s.IsChecked.Value);


    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Andrew
    Andrew avatar
    28 posts
    Member since:
    Mar 2013

    Posted 10 Apr 2013 Link to this post

    Ok.  That works for getting the control, and I can use the ispressed to get the state.  But if I want to restore the previous setting, Can I set the 'ispressed' property on the expandCollapseButton?  I can't seem to find the correct function in intellisense that would work.
  8. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 10 Apr 2013 Link to this post

    Hello,

    I believe you can set the IsChecked property for the RadToggleButton to the value you have stored.

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  9. Andrew
    Andrew avatar
    28 posts
    Member since:
    Mar 2013

    Posted 10 Apr 2013 Link to this post

    Didie,

    I just found that and was testing it out.  I got it to work with the following code.  The SaveGroupState would be called in code before any running any routines that would cause the radpropertygrid to refresh.

    Private GroupStates As New Dictionary(Of String, Boolean), GroupStateNeedsRestore As Boolean
    Private Sub SaveGroupState()
        Dim Expanders = RadPropertyGrid1.ChildrenOfType(Of RadToggleButton)().Where(Function(s) s.Name = "expandCollapseButton")
     
        For Each Expander As Telerik.Windows.Controls.RadToggleButton In Expanders
            If GroupStates.ContainsKey(Expander.Content) Then
                GroupStates(Expander.Content) = Expander.IsChecked
            Else
                GroupStates.Add(Expander.Content, Expander.IsChecked)
            End If
        Next
        GroupStateNeedsRestore = True
    End Sub
    Private Sub RestoreGroupState()
        Dim Expanders = RadPropertyGrid1.ChildrenOfType(Of RadToggleButton)().Where(Function(s) s.Name = "expandCollapseButton" AndAlso s.IsChecked.Value)
     
        For Each Expander As Telerik.Windows.Controls.RadToggleButton In Expanders
            If GroupStates.ContainsKey(Expander.Content) Then
                Expander.IsChecked = GroupStates(Expander.Content)
            End If
        Next
        GroupStateNeedsRestore = False
    End Sub
    Private Sub RadPropertyGrid1_LayoutUpdated(sender As System.Object, e As System.EventArgs) Handles RadPropertyGrid1.LayoutUpdated
        If GroupStateNeedsRestore Then RestoreGroupState()
    End Sub
  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 11 Apr 2013 Link to this post

    Hello,

    I am glad to hear you got it to work at your end. Thank you for sharing the solution with the community.

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready