I can't seem to find information on how to get the parent grid to only allow one row to be expanded at a time. There doesn't seem to be a way that I know of to iterate through all the GridViewRow objects in the parent grid and explicitly set them to IsExpanded = false and I don't see any property on the grid that would enable this sort of a feature automatically. It seems simple enough, maybe the developers can add that feature in for the next release? Until then though, how do I go about doing so?
4 Answers, 1 is accepted
0
Hi David,
Greetings,
Maya
the Telerik team
You may handle the IsExpandedChanged event of the GridViewRow and ensure that once a new item is expanded, the other one will be closed:
public MainWindow()
{
InitializeComponent();
this.clubsGrid.AddHandler(GridViewRow.IsExpandedChangedEvent, new RoutedEventHandler(OnIsExpandedChanged), true);
}
GridViewRow lastExpandedItem;
private void OnIsExpandedChanged(object sender, RoutedEventArgs e)
{
if ((e.OriginalSource as GridViewRow).IsExpanded)
{
if (lastExpandedItem != null)
{
lastExpandedItem.IsExpanded = false;
}
lastExpandedItem = e.OriginalSource as GridViewRow;
}
}
Greetings,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
David
Top achievements
Rank 1
answered on 10 Dec 2010, 05:42 PM
I tried everything except for that! Thanks, that works. Now that I effectively have single expand mode working, I need to be able to force each child grid to have the first row as the selected row when it's parent row is expanded. For example:
1) User expands row 1 of parent grid
2) User selects row 3 of row 1 parent's child grid
3) User expands parent row 2 of parent grid
4) <parent grid's row 1 automatically collapses>
5) User selects row 4 of parent row 2's child grid
6) User expands row 1 of parent grid again
7) <parent grid's row 2 automatically collapses>
7) Parent row 1's child grid still has a selection of row 3. When rows are expanded, child grids need to be forced to have a row selection of row 1 regardless of their last row selected
Is this possible? I've tried accessing ChildDataControls property of GridViewRow to maybe do it that way but that property is always null. My child grids have been loaded and the parent grid is not virtualized.
Thanks!
1) User expands row 1 of parent grid
2) User selects row 3 of row 1 parent's child grid
3) User expands parent row 2 of parent grid
4) <parent grid's row 1 automatically collapses>
5) User selects row 4 of parent row 2's child grid
6) User expands row 1 of parent grid again
7) <parent grid's row 2 automatically collapses>
7) Parent row 1's child grid still has a selection of row 3. When rows are expanded, child grids need to be forced to have a row selection of row 1 regardless of their last row selected
Is this possible? I've tried accessing ChildDataControls property of GridViewRow to maybe do it that way but that property is always null. My child grids have been loaded and the parent grid is not virtualized.
Thanks!
0
Hi David,
Maya
the Telerik team
You may set the IsSynchronizedWithCurrentItem of the child RadGridView. In this case the first row of each child grid will be selected on expanding it.
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 10 Apr 2012, 07:23 PM
Maya,
Thank you for the code; I made a slight improvement to it after noticing that if you
expand a row, collapse it, then try to expand it again, it won't expand (it's actually
expanding but then collapsing again). I just added an additional condition that checks
if you're clicking on the same row again. (See bolded text below)
public MainWindow()
{
InitializeComponent();
this.clubsGrid.AddHandler(GridViewRow.IsExpandedChangedEvent, new RoutedEventHandler(OnIsExpandedChanged), true);
}
GridViewRow lastExpandedItem;
private void OnIsExpandedChanged(object sender, RoutedEventArgs e)
{
if ((e.OriginalSource as GridViewRow).IsExpanded)
{
if (lastExpandedItem != null && lastExpandedItem != e.OriginalSource as GridViewRow)
{
lastExpandedItem.IsExpanded = false;
}
lastExpandedItem = e.OriginalSource as GridViewRow;
}
}