wpf-devexpress-dot-xpf-dot-grid-dot-gridcontrol.md
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
public DataViewBase View { get; set; }
Public Property View As DataViewBase
| Type | Description |
|---|---|
| DataViewBase |
A DataViewBase descendant that specifies the grid view used to display data.
|
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.
how-to-bind-wpf-grid-to-data/CS/CodeBehind/EFCore/LocalData/MainWindow.xaml#L9
<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
<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
<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
</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
<dxg:GridControl AutoGenerateColumns="AddNew">
<dxg:GridControl.View>
<dxg:TableView ShowGroupPanel="False"/>
protected void GridLoaded(object sender, RoutedEventArgs e) {
if(!(this.AssociatedObject.View is TreeListView)) {
return;
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
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
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
protected TableView View {
get { return (TableView)AssociatedObject.View; }
}
Protected Sub GridLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
If Not(TypeOf Me.AssociatedObject.View Is TreeListView) Then
Return
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
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
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
Get
Return CType(Me.AssociatedObject.View, DevExpress.Xpf.Grid.TableView)
End Get
See Also