Export (0) Print
Expand All
Expand Minimize

DataGridView.DataBindingComplete Event

Occurs after a data-binding operation has finished.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public event DataGridViewBindingCompleteEventHandler DataBindingComplete

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 handling events, see Consuming Events.

The following code example illustrates the use of this event. 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();
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft