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

How to: Customize Automatically Generated Columns

  • 4 minutes to read

The following example shows how to customize automatically generated columns.In this example, the ColumnsPopulated event is handled to hide the 'ID' column, and specify the sorting order of the first visible column.Starting with version 2013 vol 1 the GridControl.ColumnsPopulated event is marked as obsolete. The GridControl.AutoGeneratedColumns event should be used instead. Moreover, in 13.1, this example includes two ways for setting templates in code-behind.

<Window x:Class="E2019.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:local="clr-namespace:E2019"
        Title="Window" Height="200" Width="470">
    <Window.Resources>
        <local:IssueTypeForegroundConverter x:Key="IssueTypeForegroundConverter"/>
        <DataTemplate x:Key="IssueNameTemplate">
            <dxe:TextEdit x:Name="PART_Editor" Foreground="Blue"/>
        </DataTemplate>
        <DataTemplate x:Key="IssueTypeTemplate">
            <dxe:TextEdit x:Name="PART_Editor" Foreground="{Binding Path=Value, Converter={StaticResource IssueTypeForegroundConverter}}"/>
        </DataTemplate>
    </Window.Resources>
    <Grid>
       <dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew" AutoGeneratedColumns="OnColumnsGenerated">
          <dxg:GridControl.View>
             <dxg:TableView Name="tableView1" AutoWidth="True" />
          </dxg:GridControl.View>
       </dxg:GridControl>
    </Grid>
</Window>