Bagikan melalui


DataGrid.AutoGeneratingColumn Kejadian

Definisi

Terjadi ketika kolom individual dibuat secara otomatis.

public:
 event EventHandler<System::Windows::Controls::DataGridAutoGeneratingColumnEventArgs ^> ^ AutoGeneratingColumn;
public event EventHandler<System.Windows.Controls.DataGridAutoGeneratingColumnEventArgs> AutoGeneratingColumn;
member this.AutoGeneratingColumn : EventHandler<System.Windows.Controls.DataGridAutoGeneratingColumnEventArgs> 
Public Custom Event AutoGeneratingColumn As EventHandler(Of DataGridAutoGeneratingColumnEventArgs) 
Public Event AutoGeneratingColumn As EventHandler(Of DataGridAutoGeneratingColumnEventArgs) 

Jenis Acara

Contoh

Contoh berikut menunjukkan cara membuat kolom secara otomatis dan mengubah kolom pada waktu pembuatan di penanganan AutoGeneratingColumn aktivitas.

<!-- 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

Keterangan

Anda dapat mengubah atau membatalkan kolom yang sedang dibuat di penanganan AutoGeneratingColumn aktivitas.

Ketika semua kolom dibuat secara otomatis, peristiwa terjadi AutoGeneratedColumns .

Berlaku untuk

Lihat juga