다음을 통해 공유


DataGridAutoGeneratingColumnEventArgs.Column Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the generated column.

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

Syntax

'Declaration
Public Property Column As DataGridColumn
public DataGridColumn Column { get; set; }

Property Value

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

Remarks

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

Examples

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 Sub dataGrid1_AutoGeneratingColumn(ByVal sender As System.Object, ByVal e As System.Windows.Controls.DataGridAutoGeneratingColumnEventArgs)
    ' Modify the header of the Name column.
    If e.Column.Header.ToString() = "Name" Then
        e.Column.Header = "Task"
    End If
    '  Replace the DueDate column with a custom template column.
    If e.PropertyName = "DueDate" Then
        ' Create a new template column.
        Dim templateColumn As New DataGridTemplateColumn
        templateColumn.Header = "Due Date"
        templateColumn.CellTemplate = Me.Resources("dueDateCellTemplate")
        templateColumn.CellEditingTemplate = Me.Resources("dueDateCellEditingTemplate")
        templateColumn.SortMemberPath = "DueDate"
        ' ...
        ' Replace the auto-generated column with the templateColumn.
        e.Column = templateColumn

    End If
    ' Cancel AutoGeneration of all boolean columns.
    If e.PropertyType Is GetType(Boolean) Then
        e.Cancel = True
    End If
End Sub
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;
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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