wpf-devexpress-dot-xpf-dot-grid-dot-gridcontrol-dot-getvisibledetail-x28-system-dot-int32-x29.md
Returns the currently visible detail data control identified by its master row.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public DataControlBase GetVisibleDetail(
int rowHandle
)
Public Function GetVisibleDetail(
rowHandle As Integer
) As DataControlBase
| Name | Type | Description |
|---|---|---|
| rowHandle | Int32 |
An integer value identifying the row by its handle.
|
| Type | Description |
|---|---|
| DataControlBase |
A DataControlBase descendant which displays detail data. null ( Nothing in Visual Basic) if the currently visible detail is not represented by a DataControlDetailDescriptor.
|
When you set up a master-detail hierarchy within a GridControl, you create Detail Descriptor objects which contain settings used to create actual detail controls. While there’s a single Detail Descriptor (template) per data relation, there can be multiple detail controls - one per each expanded detail.
The GetVisibleDetail method returns the actual data control that displays detail data for the specified master row. This can be any DataControlBase descendant, but it will typically be a GridControl. Note that the method returns the control only if it’s currently visible (resides within an expanded detail).
This example demonstrates how to expand and collapse the GridControl‘s master rows in code. The example contains the following buttons:
The CTRL+* shortcut is bound to toggle the focused master row’s expanded state.
View Example: Expand and Collapse Master Rows
The following table lists members used in this example:
| Member | Description |
|---|---|
| GridControl.CollapseMasterRow | Collapses the detail section for the specified row. |
| GridControl.ExpandMasterRow | Expands the specified master row and, optionally, shows the specified Detail. |
| GridControl.IsMasterRowExpanded | Determines the specified master row’s expanded state and, optionally, the specified Detail’s visibility. |
| GridControl.SetMasterRowExpanded | Changes the expanded state for a specified master row and, optionally, shows a specified Detail. |
<dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew" Grid.Column="0">
<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True" ShowGroupPanel="False" PreviewKeyDown="TableView_KeyDown"/>
</dxg:GridControl.View>
<dxg:GridControl.DetailDescriptor>
<dxg:DataControlDetailDescriptor ItemsSourcePath="Orders">
<dxg:DataControlDetailDescriptor.DataControl>
<dxg:GridControl AutoGenerateColumns="AddNew">
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" ShowGroupPanel="False"/>
</dxg:GridControl.View>
</dxg:GridControl>
</dxg:DataControlDetailDescriptor.DataControl>
</dxg:DataControlDetailDescriptor>
</dxg:GridControl.DetailDescriptor>
</dxg:GridControl>
<StackPanel Grid.Column="1" Orientation="Vertical" Margin="10,10,10,10">
<Button Click="ExpandAll" Content="Expand All" Margin="0,10,0,0"/>
<Button Click="CollapseAll" Content="Collapse All" Margin="0,10,0,0"/>
<Button Click="CollapseAllButThis" Content="Collapse All But This" Margin="0,10,0,0"/>
<TextBlock TextWrapping="Wrap" Margin="0,30,0,0">
Press <Bold>CTRL+*</Bold> to toggle the focused master row's expanded state.
</TextBlock>
</StackPanel>
private void TableView_KeyDown(object sender, KeyEventArgs e) {
TableView view = sender as TableView;
// Avoid key processing when focus is within detail views or when a group row is focused:
if (!view.IsFocusedView || view.FocusedRowHandle < 0)
return;
// Process CTRL+* key combination:
if (e.Key == Key.Multiply && ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)) {
bool finalExpandedState = !view.Grid.IsMasterRowExpanded(view.FocusedRowHandle);
view.Grid.SetMasterRowExpanded(view.FocusedRowHandle, finalExpandedState);
e.Handled = true;
}
}
void ExpandAll(object sender, RoutedEventArgs e) {
for (int i = 0; i < grid.VisibleRowCount; i++) {
var rowHandle = grid.GetRowHandleByVisibleIndex(i);
grid.ExpandMasterRow(rowHandle);
}
}
void CollapseAll(object sender, RoutedEventArgs e) {
for (int i = 0; i < grid.VisibleRowCount; i++) {
var rowHandle = grid.GetRowHandleByVisibleIndex(i);
grid.CollapseMasterRow(rowHandle);
}
}
void CollapseAllButThis(object sender, RoutedEventArgs e) {
for (int i = 0; i < grid.VisibleRowCount; i++) {
var rowHandle = grid.GetRowHandleByVisibleIndex(i);
var detailGrid = grid.GetVisibleDetail(rowHandle);
if (detailGrid != null) {
var detailView = ((GridControl)detailGrid).View;
var focusedDetailRowHandle = ((TableView)detailView).FocusedRowHandle;
if (focusedDetailRowHandle == DataControlBase.InvalidRowHandle && rowHandle != view.FocusedRowHandle)
grid.CollapseMasterRow(rowHandle);
}
}
}
Private Sub TableView_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
Dim view As TableView = TryCast(sender, TableView)
' Avoid key processing when focus is within detail views or when a group row is focused:
If Not view.IsFocusedView OrElse view.FocusedRowHandle < 0 Then Return
' Process CTRL+* key combination:
If e.Key = Key.Multiply AndAlso (Keyboard.Modifiers And ModifierKeys.Control) = ModifierKeys.Control Then
Dim finalExpandedState As Boolean = Not view.Grid.IsMasterRowExpanded(view.FocusedRowHandle)
view.Grid.SetMasterRowExpanded(view.FocusedRowHandle, finalExpandedState)
e.Handled = True
End If
End Sub
Private Sub ExpandAll(ByVal sender As Object, ByVal e As RoutedEventArgs)
For i As Integer = 0 To Me.grid.VisibleRowCount - 1
Dim rowHandle = Me.grid.GetRowHandleByVisibleIndex(i)
Me.grid.ExpandMasterRow(rowHandle)
Next
End Sub
Private Sub CollapseAll(ByVal sender As Object, ByVal e As RoutedEventArgs)
For i As Integer = 0 To Me.grid.VisibleRowCount - 1
Dim rowHandle = Me.grid.GetRowHandleByVisibleIndex(i)
Me.grid.CollapseMasterRow(rowHandle)
Next
End Sub
Private Sub CollapseAllButThis(ByVal sender As Object, ByVal e As RoutedEventArgs)
For i As Integer = 0 To Me.grid.VisibleRowCount - 1
Dim rowHandle = Me.grid.GetRowHandleByVisibleIndex(i)
Dim detailGrid = Me.grid.GetVisibleDetail(rowHandle)
If detailGrid IsNot Nothing Then
Dim detailView = CType(detailGrid, GridControl).View
Dim focusedDetailRowHandle = CType(detailView, TableView).FocusedRowHandle
If focusedDetailRowHandle = DataControlBase.InvalidRowHandle AndAlso rowHandle <> Me.view.FocusedRowHandle Then Me.grid.CollapseMasterRow(rowHandle)
End If
Next
End Sub
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetVisibleDetail(Int32) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
wpf-data-grid-expand-and-collapse-master-rows/CS/WpfApplication21/MainWindow.xaml.cs#L47
var rowHandle = grid.GetRowHandleByVisibleIndex(i);
var detailGrid = grid.GetVisibleDetail(rowHandle);
if (detailGrid != null) {
wpf-data-grid-expand-and-collapse-master-rows/VB/WpfApplication21/MainWindow.xaml.vb#L46
Dim rowHandle = Me.grid.GetRowHandleByVisibleIndex(i)
Dim detailGrid = Me.grid.GetVisibleDetail(rowHandle)
If detailGrid IsNot Nothing Then
See Also
GetDetail(Int32, DataControlDetailDescriptor)