Export (0) Print
Expand All

DataGridAutoGeneratingColumnEventArgs.Column Property

Gets the generated column.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)

public DataGridColumn Column { get; set; }

Property Value

Type: System.Windows.Controls.DataGridColumn
The generated column.

The Column property can be used to modify properties of the column that is being generated.

The following code example demonstrates how to use the Column property. This example is part of a larger example available in the How to: Customize Auto-Generated Columns in the DataGrid Control topic.

private void dataGrid1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    // Modify the header of the Name column.
    if (e.Column.Header.ToString() == "Name")
        e.Column.Header = "Task";
    // Replace the DueDate column with a custom template column.
    if (e.PropertyName == "DueDate")
        // Create a new template column.
        DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
        templateColumn.Header = "Due Date";
        templateColumn.CellTemplate = (DataTemplate)Resources["dueDateCellTemplate"];
        templateColumn.CellEditingTemplate = (DataTemplate)Resources["dueDateCellEditingTemplate"];
        templateColumn.SortMemberPath = "DueDate";
        // ...
        // Replace the auto-generated column with the templateColumn.
        e.Column = templateColumn;

    // Cancel AutoGeneration of all boolean columns.
    if (e.PropertyType == typeof(bool))
        e.Cancel = true;


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2015 Microsoft