Skip to main content
A newer version of this page is available. .

ListBoxItemCollection.BeginUpdate() Method

Locks the ListBoxItemCollection by preventing change notifications from being fired, preventing visual updates until the EndUpdate method is called.

Namespace: DevExpress.XtraEditors.Controls

Assembly: DevExpress.XtraEditors.v18.2.dll

Declaration

public virtual void BeginUpdate()

Remarks

Use BeginUpdate along with the EndUpdate method to prevent superfluous change notifications from being sent while performing multiple changes on the ListBoxItemCollection. Enclose the code that performs multiple changes on the collection with the BeginUpdate and EndUpdate methods. The result will be that the change notification will fire only once, triggered by the EndUpdate method.

The BeginUpdate and EndUpdate methods use an internal counter to implement the update functionality. The counter’s initial value is 0. The BeginUpdate method increments the counter. EndUpdate decrements the counter, and if its new value is zero, change notification is enabled. Note that each call to BeginUpdate must be paired with a call to EndUpdate. If you call BeginUpdate but forget to call EndUpdate afterwards or EndUpdate is not called because an exception occurred, change notifications will no longer be fired. To ensure that EndUpdate is always called even if an exception occurs, use the try…finally statement.

The BeginUpdate and ListBoxItemCollection.EndUpdate methods are in effect when changing the ListBoxControl.Items collection of an unbound ListBoxControl.


listBoxControl1.Items.BeginUpdate();
try {
    listBoxControl1.Items.Clear();
    for(int i = 0; i < 1000; i++)
        listBoxControl1.Items.Add(i);
}
finally {
    listBoxControl1.Items.EndUpdate();
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the BeginUpdate() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also