DataGridView.DataBindingComplete 事件

定義

發生於資料繫結作業完成之後。Occurs after a data-binding operation has finished.

public:
 event System::Windows::Forms::DataGridViewBindingCompleteEventHandler ^ DataBindingComplete;
public event System.Windows.Forms.DataGridViewBindingCompleteEventHandler DataBindingComplete;
member this.DataBindingComplete : System.Windows.Forms.DataGridViewBindingCompleteEventHandler 
Public Custom Event DataBindingComplete As DataGridViewBindingCompleteEventHandler 

範例

下列程式碼範例說明如何使用這個事件。The following code example illustrates the use of this event. 這個範例是 DataGridViewRowContextMenuStripNeededEventArgs 類別總覽中提供之較大範例的一部分。This example is part of a larger example available in the DataGridViewRowContextMenuStripNeededEventArgs class overview.

private void dataGridView1_DataBindingComplete(object sender,
    DataGridViewBindingCompleteEventArgs e)
{
    // Hide some of the columns.
    dataGridView1.Columns["EmployeeID"].Visible = false;
    dataGridView1.Columns["Address"].Visible = false;
    dataGridView1.Columns["TitleOfCourtesy"].Visible = false;
    dataGridView1.Columns["BirthDate"].Visible = false;
    dataGridView1.Columns["HireDate"].Visible = false;
    dataGridView1.Columns["PostalCode"].Visible = false;
    dataGridView1.Columns["Photo"].Visible = false;
    dataGridView1.Columns["Notes"].Visible = false;
    dataGridView1.Columns["ReportsTo"].Visible = false;
    dataGridView1.Columns["PhotoPath"].Visible = false;

    // Disable sorting for the DataGridView.
    foreach (DataGridViewColumn i in
        dataGridView1.Columns)
    {
        i.SortMode = DataGridViewColumnSortMode.NotSortable;
    }

    dataGridView1.AutoResizeColumns();
}
Private Sub dataGridView1_DataBindingComplete(ByVal sender As Object, _
ByVal e As DataGridViewBindingCompleteEventArgs) _
Handles dataGridView1.DataBindingComplete

    ' Hide some of the columns.
    With dataGridView1
        .Columns("EmployeeID").Visible = False
        .Columns("Address").Visible = False
        .Columns("TitleOfCourtesy").Visible = False
        .Columns("BirthDate").Visible = False
        .Columns("HireDate").Visible = False
        .Columns("PostalCode").Visible = False
        .Columns("Photo").Visible = False
        .Columns("Notes").Visible = False
        .Columns("ReportsTo").Visible = False
        .Columns("PhotoPath").Visible = False
    End With

    ' Disable sorting for the DataGridView.
    Dim i As DataGridViewColumn
    For Each i In dataGridView1.Columns
        i.SortMode = DataGridViewColumnSortMode.NotSortable
    Next i

    dataGridView1.AutoResizeColumns()

End Sub

備註

當資料來源的內容變更時,或 DataSourceDataMemberBindingContext 屬性的值變更時,就會引發這個事件。This event is raised when the contents of the data source change or when the value of the DataSource, DataMember, or BindingContext property changes.

例如,處理這個事件很有用,可以根據內容更新以程式設計方式調整資料列和資料行的大小。Handling this event is useful, for example, to programmatically resize rows and columns based on content updates. 如需詳細資訊,請參閱Windows Forms DataGridView 控制項中的調整大小選項For more information, see Sizing Options in the Windows Forms DataGridView Control.

如需如何處理事件的詳細資訊,請參閱處理和引發事件For more information about how to handle events, see Handling and Raising Events.

適用於

另請參閱