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
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.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
You can find the groups with expanded state using the following approach:
radPropertyGrid.ChildrenOfType<RadToggleButton>().Where(s => s.Name ==
"expandCollapseButton"
&& s.IsChecked.Value);
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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.
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
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.
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?
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