Export (0) Print
Expand All

ComboBox.BeginUpdate Method

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 void BeginUpdate ()
public void BeginUpdate ()
public function BeginUpdate ()
Not applicable.

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 void addGrandButton_Click(object sender, System.EventArgs e) {
    comboBox1.BeginUpdate();
    for (int i = 0; i < 1000; i++) {
        comboBox1.Items.Add("New Item " + i.ToString());
    }
    comboBox1.EndUpdate();
}

private void addGrandButton_Click(Object sender, System.EventArgs e)
{
    comboBox1.BeginUpdate();
    for (int i = 0; i < 1000; i++) {
        comboBox1.get_Items().Add("New Item " + ((Int32)i).ToString());
    }
    comboBox1.EndUpdate();
} //addGrandButton_Click

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft