DataGridView.DataBindingComplete 事件

定义

在数据绑定操作完成之后发生。

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 

事件类型

DataGridViewBindingCompleteEventHandler

示例

下面的代码示例演示了此事件的用法。 此示例是类概述中提供的大型示例的 DataGridViewRowContextMenuStripNeededEventArgs 一部分。

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时,将引发此事件。

例如,处理此事件非常有用,以便基于内容更新以编程方式调整行和列的大小。 有关详细信息,请参阅 Windows 窗体 DataGridView 控件中的大小调整选项

有关如何处理事件的详细信息,请参阅 处理和引发事件

适用于

另请参阅