DataGridView.DataBindingComplete Event

Definition

Occurs after a data-binding operation has finished.

C#
public event System.Windows.Forms.DataGridViewBindingCompleteEventHandler DataBindingComplete;
C#
public event System.Windows.Forms.DataGridViewBindingCompleteEventHandler? DataBindingComplete;

Event Type

Examples

The following code example illustrates the use of this event. This example is part of a larger example available in the DataGridViewRowContextMenuStripNeededEventArgs class overview.

C#
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();
}

Remarks

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

Applies to

Produkt Versioner
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also