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)

'Declaration
Public Event DataBindingComplete As DataGridViewBindingCompleteEventHandler

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft