Skip to main content
A newer version of this page is available. .

Creating and Assigning Views

You can specify the GridControl‘s view by assigning one of the following objects to the GridControl.View property.

Note

The GridControl uses TableView by default.

Assigning a View at Design-Time

The following example shows how to assign a TreeListView to the grid control using 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>

The following image demonstrates the result.

Creating and assigning views treelist

Assigning a View at Run-Time

The following example shows how to assign a CardView to the grid control in code.

using DevExpress.Xpf.Grid;

// ...
public Window1() {
    InitializeComponent();
    grid.View = CreateCardView();
    grid.DataSource = new nwindProductsDataSetTableAdapters.ProductsTableAdapter().GetData();
}
private CardView CreateCardView() {
    CardView view = new CardView() {
        NavigationStyle = GridViewNavigationStyle.Cell,
        AllowGrouping = false,
        ShowColumnHeaders = false
    };
    return view;
}

The following image demonstrates the result.

Creating and assigning views CardView