How do we select all rows that are in expanded groups? For example:
1. User drags a column into the Group Panel
2. User clicks the Group Expander on two of the groups, expanding both groups so that the rows are visible
3. User clicks a "Select all Visible" button which selects all the rows in the two visible groups.
How do we implement step #3?
Thanks in advanced!
1. User drags a column into the Group Panel
2. User clicks the Group Expander on two of the groups, expanding both groups so that the rows are visible
3. User clicks a "Select all Visible" button which selects all the rows in the two visible groups.
How do we implement step #3?
Thanks in advanced!
4 Answers, 1 is accepted
0
Hello Daniel,
In order to fulfill your goal, first you will need to get all expanded rows. This can be achieved by using the ChildrenOfType<T>() extension method on GridView in conjunction with the IsExpanded property of the group row.
Please keep in mind that RadGridView has a GroupRenderMode property which supports two modes:
1) "Nested" (the default) - the grouped row is of type GridViewGroupRow.
2) "Flat" - the grouped row is of type GroupHeaderRow.
When you get all rows you will need to clear the SelectedItems collection of GridView and then add all the items to it.
In addition, I set the EnableLostFocusSelectedState and SelectionMode properties of the GridView respectively to "False" and "Multiple".
Also, I attached a sample project that demonstrates the suggested approach.
I hope this helps.
Regards,
Boris Penev
Telerik
In order to fulfill your goal, first you will need to get all expanded rows. This can be achieved by using the ChildrenOfType<T>() extension method on GridView in conjunction with the IsExpanded property of the group row.
Please keep in mind that RadGridView has a GroupRenderMode property which supports two modes:
1) "Nested" (the default) - the grouped row is of type GridViewGroupRow.
2) "Flat" - the grouped row is of type GroupHeaderRow.
When you get all rows you will need to clear the SelectedItems collection of GridView and then add all the items to it.
private
void
Button1_Click(
object
sender, RoutedEventArgs e)
{
if
(
this
.clubsGrid.GroupCount > 0)
{
// GroupRenderMode = "Nested"
var gridViewGroupRows =
this
.clubsGrid.ChildrenOfType<GridViewGroupRow>().Where(row => row.IsExpanded);
if
(gridViewGroupRows.Count() > 0)
{
this
.clubsGrid.SelectedItems.Clear();
foreach
(GridViewGroupRow row
in
gridViewGroupRows)
{
foreach
(Club item
in
row.Items)
{
this
.clubsGrid.SelectedItems.Add(item);
}
}
}
//// GroupRenderMode = "Flat"
var groupHeaderRows =
this
.clubsGrid.ChildrenOfType<GroupHeaderRow>().Where(row => row.IsExpanded);
if
(groupHeaderRows.Count() > 0)
{
this
.clubsGrid.SelectedItems.Clear();
foreach
(GroupHeaderRow row
in
groupHeaderRows)
{
foreach
(Club item
in
row.GroupViewModel.Group.Items)
{
this
.clubsGrid.SelectedItems.Add(item);
}
}
}
}
}
In addition, I set the EnableLostFocusSelectedState and SelectionMode properties of the GridView respectively to "False" and "Multiple".
Also, I attached a sample project that demonstrates the suggested approach.
I hope this helps.
Regards,
Boris Penev
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Daniel
Top achievements
Rank 1
answered on 24 Jul 2014, 05:27 PM
Hi Boris,
Unfortunately, this code does not work when I add more than one column to the Group Panel. In the sample code that you provided:
1. Drag the Name column to the Group Panel
2. Drag the Est. column to the Group Panel
3. Open the "Arsenal" group and the "1886" subgroup
4. Click the "Select All Visible Rows" button
5. Observe Crash
Here is the exception for when GroupRenderMode = "Nested"
Unable to cast object of type 'Telerik.Windows.Data.GroupingImpl`2[System.DateTime,GridViewSelectAllRowsInExpanedeGroups.Club]' to type 'GridViewSelectAllRowsInExpanedeGroups.Club'.
Here is the exception for when GroupRenderMode = "Flat"
Unable to cast object of type 'Telerik.Windows.Data.GroupingImpl`2[System.Int32,GridViewSelectAllRowsInExpanedeGroups.Club]' to type 'GridViewSelectAllRowsInExpanedeGroups.Club'.
While I have you here, this is the first time I've seen the GroupRenderMode property. I understand the mechanism in the back is different, but does it behave the same from the user's perspective?
Thanks again.
Unfortunately, this code does not work when I add more than one column to the Group Panel. In the sample code that you provided:
1. Drag the Name column to the Group Panel
2. Drag the Est. column to the Group Panel
3. Open the "Arsenal" group and the "1886" subgroup
4. Click the "Select All Visible Rows" button
5. Observe Crash
Here is the exception for when GroupRenderMode = "Nested"
Unable to cast object of type 'Telerik.Windows.Data.GroupingImpl`2[System.DateTime,GridViewSelectAllRowsInExpanedeGroups.Club]' to type 'GridViewSelectAllRowsInExpanedeGroups.Club'.
Here is the exception for when GroupRenderMode = "Flat"
Unable to cast object of type 'Telerik.Windows.Data.GroupingImpl`2[System.Int32,GridViewSelectAllRowsInExpanedeGroups.Club]' to type 'GridViewSelectAllRowsInExpanedeGroups.Club'.
While I have you here, this is the first time I've seen the GroupRenderMode property. I understand the mechanism in the back is different, but does it behave the same from the user's perspective?
Thanks again.
0
Accepted
Hello Daniel,
You can easily fix these errors by changing the Club type in the foreach loops to var.
As for your second question, the GroupRenderMode property changes only the mechanism for generating the containers of the items.
Regards,
Boris Penev
Telerik
You can easily fix these errors by changing the Club type in the foreach loops to var.
// GroupRenderMode = "Nested"
foreach
(var item
in
row.Items)
{
this
.clubsGrid.SelectedItems.Add(item);
}
// GroupRenderMode = "Flat"
foreach
(var item
in
row.GroupViewModel.Group.Items)
{
this
.clubsGrid.SelectedItems.Add(item);
}
As for your second question, the GroupRenderMode property changes only the mechanism for generating the containers of the items.
Regards,
Boris Penev
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
A
Top achievements
Rank 1
answered on 28 Oct 2018, 04:13 PM
How this can be done by Clientside?? I have a check box column in RadGrid. When i click on check all option in header, rows in expanded groups should be selected. I want this in Client side. Is it Possible??