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

Collapsed Groups lose Collapse on Refresh?

10 Answers 286 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 04 Apr 2013, 06:23 PM
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.

10 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 05 Apr 2013, 12:32 PM
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.

0
Andrew
Top achievements
Rank 1
answered on 05 Apr 2013, 01:01 PM
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?
0
Andrew
Top achievements
Rank 1
answered on 05 Apr 2013, 03:05 PM
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.
0
Dimitrina
Telerik team
answered on 08 Apr 2013, 01:31 PM
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.

0
Andrew
Top achievements
Rank 1
answered on 10 Apr 2013, 03:15 PM
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.
0
Accepted
Dimitrina
Telerik team
answered on 10 Apr 2013, 03:17 PM
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.

0
Andrew
Top achievements
Rank 1
answered on 10 Apr 2013, 03:37 PM
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
0
Dimitrina
Telerik team
answered on 11 Apr 2013, 03:43 PM
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.

0
maria
Top achievements
Rank 1
answered on 01 Jun 2018, 10:41 AM

Hi Dimitrina. I am also facing exactly same issue. I tried your solution to find the groups with expanded state

IEnumerable<RadToggleButton> temp_list = grid.ChildrenOfType<RadToggleButton>().Where(s => s.Name == "expandCollapseButton" && s.IsChecked.Value == false);

But I am getting an empty list every time. 

Please guide why am I getting empty list?

 

 

0
Stefan
Telerik team
answered on 05 Jun 2018, 02:18 PM
Hello Maria,

This is due to the fact, that initially the groups are expanded. You need to ensure that fetching the buttons that have their IsChecked property set to false is done after the groups are already collapsed.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
PropertyGrid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Andrew
Top achievements
Rank 1
maria
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or