This documentation is archived and is not being maintained.

ComboBox.EndUpdate Method

Resumes painting the ComboBox control after painting is suspended by the BeginUpdate method.

[Visual Basic]
Public Sub EndUpdate()
[C#]
public void EndUpdate();
[C++]
public: void EndUpdate();
[JScript]
public function EndUpdate();

Remarks

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 flickered drawing of the ComboBox when a large number of items are being added to the list.

Example

[Visual Basic, C#, C++] The following example illustrates the usage of the BeginUpdate and EndUpdate methods. The example is part of a runnable code sample in the ComboBox class overview.

[Visual Basic] 
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

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

[C++] 
private:
    void addGrandButton_Click(Object* /*sender*/, System::EventArgs* /*e*/) {
        comboBox1->BeginUpdate();
        for (int i = 0; i < 1000; i++) {
            comboBox1->Items->Add(String::Concat(S"New Item ", i.ToString()));
        }
        comboBox1->EndUpdate();
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ComboBox Class | ComboBox Members | System.Windows.Forms Namespace

Show: