Back to Devexpress

GridControl.View Property

wpf-devexpress-dot-xpf-dot-grid-dot-gridcontrol.md

latest10.9 KB
Original Source

GridControl.View Property

Gets or sets the grid’s view. This is a dependency property.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public DataViewBase View { get; set; }
vb
Public Property View As DataViewBase

Property Value

TypeDescription
DataViewBase

A DataViewBase descendant that specifies the grid view used to display data.

|

Remarks

Tip

Topic : Views

The GridControl does not actually display data itself. It uses a View to display data from the bound data source. A View specifies how records and record fields are arranged.

xaml
<dxg:GridControl AutoGenerateColumns="AddNew" ItemsSource="{Binding Customers}" >
    <dxg:GridControl.View>
        <dxg:TableView />
    </dxg:GridControl.View>
    <dxg:GridColumn FieldName="Name" Width="3*"/>
    <dxg:GridColumn FieldName="City" Width="3*"/>
    <dxg:GridColumn FieldName="Visits" Width="*"/>
    <dxg:GridColumn FieldName="BirthDate" Width="2*"/>
</dxg:GridControl>

When the GridControl is created, it initializes the View property with a TableView object. To display data using a Card View, you should create a corresponding View object and assign it to the View property. To display hierarchical data in a tree, use the TreeListView.

xaml
<dxg:GridControl ItemsSource="{Binding Employees}">
    <dxg:GridControl.View>
        <dxg:TreeListView KeyFieldName="ID" ParentFieldName="ParentID"/>
    </dxg:GridControl.View>
    <dxg:GridColumn FieldName="Name"/>
    <dxg:GridColumn FieldName="Position"/>
    <dxg:GridColumn FieldName="Department"/>
</dxg:GridControl>

Use the ValueFactoryExtension if you specify the View property in the style applied to multiple GridControls:

xaml
<Window.Resources>
    <Style TargetType="dxg:GridControl" x:Key="gridStyle">
        <!-- ... -->
        <Setter Property="View">
            <Setter.Value>
                <dxmvvm:ValueFactory>
                    <DataTemplate>
                        <dxg:TreeListView KeyFieldName="ID" ParentFieldName="ParentID" 
                                          AutoWidth="True" AutoExpandAllNodes="True"/>
                    </DataTemplate>
                </dxmvvm:ValueFactory>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <dxg:GridControl Style="{StaticResource gridStyle}"/>
    <dxg:GridControl Style="{StaticResource gridStyle}" Grid.Row="1"/>
</Grid>

The following code snippets (auto-collected from DevExpress Examples) contain references to the View property.

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.

how-to-bind-wpf-grid-to-data/CS/CodeBehind/EFCore/LocalData/MainWindow.xaml#L9

xml
<dxg:GridControl x:Name="grid">
    <dxg:GridControl.View>
        <dxg:TableView ShowFixedTotalSummary="True" />

wpf-data-grid-implement-crud-operations/CS/CodeBehind/EFCore/PagedAsyncSource/MainWindow.xaml#L21

xml
<dxg:GridControl x:Name="grid" Grid.Row="1">
    <dxg:GridControl.View>
        <dxg:TableView ShowUpdateRowButtons="OnCellEditorOpen" ValidateRow="OnValidateRow"

wpf-data-grid-extend-crud-operations/CS/DetailCollectionEditing/MainWindow.xaml#L21

xml
<dxg:GridControl x:Name="grid" ItemsSource="{Binding ItemsSource}" RestoreStateKeyFieldName="Id" RestoreStateOnSourceChange="True" Grid.Row="1">
    <dxg:GridControl.View>
        <dxg:TableView RowDoubleClickCommand="{Binding RowDoubleClickCommand, ElementName=EditFormBehavior}" NavigationStyle="Row" ValidateRowDeletionCommand="{Binding ValidateRowDeletionCommand}" DataSourceRefreshCommand="{Binding DataSourceRefreshCommand}" ShowFixedTotalSummary="True" />

wpf-data-grid-process-frequent-data-updates/CS/ChunkAndOptSummariesExample/MainWindow.xaml#L32

xml
</dxg:GridControl.Columns>
<dxg:GridControl.View>
    <dxg:TableView GroupSummaryDisplayMode="AlignByColumns" ShowTotalSummary="True" />

wpf-data-grid-display-different-details-based-on-master-row-data/CS/WpfApp30/MainWindow.xaml#L21

xml
<dxg:GridControl AutoGenerateColumns="AddNew">
    <dxg:GridControl.View>
        <dxg:TableView ShowGroupPanel="False"/>

wpf-grid-sync-isnodeexpanded-with-view-model/CS/DevExpress.Example04/BindableExpandingBehavior.cs#L35

csharp
protected void GridLoaded(object sender, RoutedEventArgs e) {
    if(!(this.AssociatedObject.View is TreeListView)) {
        return;

how-to-create-search-window-with-find-previous-and-find-next-buttons-in-gridcontrol-t127527/CS/DevExpress.Example01/SearchBehavior/SearchWindow.xaml.cs#L200

csharp
string searchText = this.SearchText.ToLower();
if(!(this._Grid.View is TableView)) { return; }

wpf-data-grid-create-master-detail-grid-in-code/CS/MasterDetailInCode/MainWindow.xaml.cs#L18

csharp
gridControl.ItemsSource = Employees.GetEmployees();
gridControl.View = new TableView();
((TableView)gridControl.View).AutoWidth = true;

wpf-data-grid-expand-and-collapse-master-rows/CS/WpfApplication21/MainWindow.xaml.cs#L49

csharp
if (detailGrid != null) {
    var detailView = ((GridControl)detailGrid).View;
    var focusedDetailRowHandle = ((TableView)detailView).FocusedRowHandle;

wpf-data-grid-change-background-color-for-modified-cells/CS/HighlightChangedCellBehavior.cs#L20

csharp
protected TableView View {
    get { return (TableView)AssociatedObject.View; }
}

wpf-grid-sync-isnodeexpanded-with-view-model/VB/DevExpress.Example04/BindableExpandingBehavior.vb#L40

vb
Protected Sub GridLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If Not(TypeOf Me.AssociatedObject.View Is TreeListView) Then
        Return

how-to-create-search-window-with-find-previous-and-find-next-buttons-in-gridcontrol-t127527/VB/DevExpress.Example01/SearchBehavior/SearchWindow.xaml.vb#L188

vb
Dim searchText As String = Me.SearchText.ToLower()
If Not(TypeOf _Grid.View Is TableView) Then
    Return

wpf-data-grid-create-master-detail-grid-in-code/VB/MasterDetailInCode/MainWindow.xaml.vb#L21

vb
gridControl.ItemsSource = Employees.GetEmployees()
gridControl.View = New TableView()
CType(gridControl.View, TableView).AutoWidth = True

wpf-data-grid-expand-and-collapse-master-rows/VB/WpfApplication21/MainWindow.xaml.vb#L48

vb
If detailGrid IsNot Nothing Then
    Dim detailView = CType(detailGrid, GridControl).View
    Dim focusedDetailRowHandle = CType(detailView, TableView).FocusedRowHandle

wpf-data-grid-change-background-color-for-modified-cells/VB/HighlightChangedCellBehavior.vb#L34

vb
Get
    Return CType(Me.AssociatedObject.View, DevExpress.Xpf.Grid.TableView)
End Get

See Also

GridControl Class

GridControl Members

DevExpress.Xpf.Grid Namespace