DataGrid.AutoGenerateColumns 속성

정의

열을 자동으로 만들지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool AutoGenerateColumns { bool get(); void set(bool value); };
public bool AutoGenerateColumns { get; set; }
member this.AutoGenerateColumns : bool with get, set
Public Property AutoGenerateColumns As Boolean

속성 값

열이 자동으로 만들어지면 true이고, 그렇지 않으면 false입니다. 등록된 기본값은 true입니다. 값에 영향을 줄 수 있는 요소에 대한 자세한 내용은 DependencyProperty를 참조하십시오.

예제

다음 예제에서는 이벤트 처리기에서 AutoGeneratingColumn 만들 때 열을 자동으로 생성하고 열을 변경하는 방법을 보여 줍니다.

<!-- The DataGrid.DataContext is a DataTable that contains a list of customers.  The DataTable columns are  
     Title, FirstName, MiddleName, LastName, Suffix, CompanyName, EmailAddress, and Phone.-->
<DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="True" AutoGeneratingColumn="DG1_AutoGeneratingColumn" />
//Access and update columns during autogeneration
private void DG1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
    string headername = e.Column.Header.ToString();

    //Cancel the column you don't want to generate
    if (headername == "MiddleName")
    {
        e.Cancel = true;
    }

    //update column details when generating
    if (headername == "FirstName")
    {
        e.Column.Header = "First Name";
    }
    else if (headername == "LastName")
    {
        e.Column.Header = "Last Name";
    }
    else if (headername == "EmailAddress")
    {
        e.Column.Header = "Email";
    }
}
'Access and update columns during autogeneration
Private Sub DG1_AutoGeneratingColumn(ByVal sender As Object, ByVal e As DataGridAutoGeneratingColumnEventArgs)
    Dim headername As String = e.Column.Header.ToString()
    'Cancel the column you don't want to generate
    If headername = "MiddleName" Then
        e.Cancel = True
    End If

    'update column details when generating
    If headername = "FirstName" Then
        e.Column.Header = "First Name"
    ElseIf headername = "LastName" Then
        e.Column.Header = "Last Name"
    ElseIf headername = "EmailAddress" Then
        e.Column.Header = "Email"
    End If
End Sub

설명

를 로 true 설정 AutoGenerateColumns 하면 false 자동 생성된 열이 생성되거나 제거됩니다. 속성이 로 AutoGenerateColumns 설정 trueAutoGeneratingColumn 되면 생성되는 각 열에 대해 이벤트가 발생합니다. 이벤트 처리기에서 생성되는 열을 변경하거나 취소할 AutoGeneratingColumn 수 있습니다.

모든 열의 자동 생성이 완료되면 AutoGeneratedColumns 이벤트가 발생합니다.

참고

DataGrid 는 원본이 XML 데이터일 때 열을 자동으로 생성할 수 없습니다. 이 경우 사용자 지정 Columns 컬렉션을 만듭니다. 예제를 보려면 DataGridTextColumn를 참조하세요.

적용 대상

추가 정보