ComboBox.BeginUpdate Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Maintains performance when items are added to the ComboBox one at a time.

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

Public Sub BeginUpdate

This method prevents the control from painting until the EndUpdate method is called.

The preferred way to add items to the ComboBox is to use the AddRange method of the ComboBox.ObjectCollection class (through the Items property of the ComboBox). This enables you to add an array of items to the list at one time. However, if you want to add items one at a time using the Add method of the ComboBox.ObjectCollection class, you can use the BeginUpdate method to prevent the control from repainting the ComboBox each time an item is added to the list. Once you have completed the task of adding items to the list, call the EndUpdate method to enable the ComboBox to repaint. This way of adding items can prevent flicker during the drawing of the ComboBox when a large number of items are being added to the list.

The following code example shows the usage of the BeginUpdate and EndUpdate methods. The example is part of a complete code example in the ComboBox class overview.

Private Sub addGrandButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    comboBox1.BeginUpdate()
    Dim I As Integer
    For I = 0 To 1000
        comboBox1.Items.Add("New Item " + i.ToString())
    Next
    comboBox1.EndUpdate()
End Sub

.NET Framework
Available since 1.1
Return to top
Show: