Skip to content

Commit 6860c1a

Browse files
Update Readme file (new template)
1 parent 5f6e515 commit 6860c1a

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

Images/expanded-rows.jpg

55.6 KB
Loading

Readme.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,73 @@
44
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
55
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
66
<!-- default badges end -->
7-
<!-- default file list -->
8-
*Files to look at*:
97

10-
* [GroupChildSelector.cs](./CS/GridGroupSelect/GroupChildSelector.cs) (VB: [GroupChildSelector.vb](./VB/GridGroupSelect/GroupChildSelector.vb))
8+
# WPF Data Grid – Select Child Rows When a User Clicks or Expands a Group Row
9+
10+
This example selects all child rows in a group when a user expands a group row or clicks a group row.
11+
12+
![Select Child Rows When a User Clicks or Expands a Group Row](./Images/expanded-rows.jpg)
13+
14+
Use this technique when you need to:
15+
16+
* Select all children after a group expands.
17+
* Select children on a group-row click.
18+
* Apply recursive selection in nested groups.
19+
20+
## Implementation Details
21+
22+
### Attached Behavior
23+
24+
Specify the `GroupChildSelector.Mode` attached property for the [`TableView`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.TableView) and set the property to one of the following modes:
25+
26+
* `None` — no selection.
27+
* `Child` — select direct children.
28+
* `Hierarchical` — select all descendants in expanded subgroups.
29+
30+
The child-row selection logic works with two events:
31+
32+
* `PreviewMouseLeftButtonUp` - fires when a user clicks a group row.
33+
* [`GroupRowExpanding`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.GridControl.GroupRowExpanding) - fires when a user expands a group.
34+
35+
When either event occurs, the child-row selection logic selects all child rows in that group and calls [`BeginSelection`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.DataControlBase.BeginSelection) and [`EndSelection`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.DataControlBase.EndSelection) methods to apply the changes in one step.
36+
37+
```xaml
38+
<dxg:GridControl>
39+
<dxg:GridControl.View>
40+
<dxg:TableView
41+
local:GroupChildSelector.Mode="Hierarchical" />
42+
</dxg:GridControl.View>
43+
</dxg:GridControl>
44+
```
45+
46+
### Selection Logic
47+
48+
The `GroupChildSelector` calls the `SelectChild(grid, groupRowHandle)` method to select all child rows in a group. In `Hierarchical` mode, if a child row is an expanded group, the method calls itself to select that group’s child rows. The code calls the `BeginSelection` method before changes and the `EndSelection` method after changes to update the selection in a single step.
49+
50+
### Data Setup
51+
52+
In the `MainWindow` constructor, the `DataContext` is set to the collection returned by the `SampleDataRow.CreateRows()` method. This method creates 100 data rows with `Id`, `Group`, `Name`, and `HasFlag` fields.
53+
54+
## Files to Review
55+
1156
* [MainWindow.xaml](./CS/GridGroupSelect/MainWindow.xaml) (VB: [MainWindow.xaml](./VB/GridGroupSelect/MainWindow.xaml))
1257
* [MainWindow.xaml.cs](./CS/GridGroupSelect/MainWindow.xaml.cs) (VB: [MainWindow.xaml.vb](./VB/GridGroupSelect/MainWindow.xaml.vb))
58+
* [GroupChildSelector.cs](./CS/GridGroupSelect/GroupChildSelector.cs) (VB: [GroupChildSelector.vb](./VB/GridGroupSelect/GroupChildSelector.vb))
1359
* [SampleDataRow.cs](./CS/GridGroupSelect/SampleDataRow.cs) (VB: [SampleDataRow.vb](./VB/GridGroupSelect/SampleDataRow.vb))
14-
<!-- default file list end -->
15-
# WPF Grid - Select child rows when a user clicks or expands a group row
1660

61+
## Documentation
1762

18-
<p>This example demonstrates how to select all child rows in a group when a group row is expanded or clicked.</p>
63+
* [Data Grid](https://docs.devexpress.com/WPF/6084/controls-and-libraries/data-grid)
64+
* [GridControl](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.GridControl)
65+
* [GridColumn](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.BandBase.GridColumn)
66+
* [TableView](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.TableView)
1967

20-
<br/>
68+
## More Examples
2169

70+
* [WPF Data Grid - Specify Custom Content for Headers Displayed in the Column Chooser](https://github.com/DevExpress-Examples/wpf-data-grid-custom-content-for-column-chooser-headers)
71+
* [WPF Data Grid - Bind to Dynamic Data](https://github.com/DevExpress-Examples/wpf-bind-gridcontrol-to-dynamic-data)
72+
* [Implement CRUD Operations in the WPF Data Grid](https://github.com/DevExpress-Examples/wpf-data-grid-implement-crud-operations)
73+
* [WPF Grid - Resize Rows Using a Splitter](https://github.com/sergepilipchuk/wpf-grid-resize-rows-using-splitter)
2274

2375
<!-- feedback -->
2476
## Does this example address your development requirements/objectives?

0 commit comments

Comments
 (0)