Skip to main content

DevExpress v24.1 Update — Your Feedback Matters

Our What's New in v24.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

GridControl.View Property

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

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.1.dll

NuGet Package: DevExpress.Wpf.Grid.Core

#Declaration

public DataViewBase View { get; set; }

#Property Value

Type Description
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.

<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.

<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:

<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.

See Also