listBox1.BeginUpdate(); for (int i = 0; i < 1000; i++) { listBox1.Items.Add("Item " + i); } listBox1.EndUpdate();
private void AddItemsToListBox(ListBox listBox, ListIn this example, a method called AddItemsToListBox is defined that takes a ListBox control and a List of strings as parameters. The BeginUpdate method is called at the beginning of the method, and the EndUpdate method is called at the end. This method can be called from other parts of the code to add items to a ListBox control without having to manually call the BeginUpdate and EndUpdate methods each time. The ListBox.BeginUpdate method is part of the System.Windows.Forms namespace, which is a part of the .NET Framework library.items) { listBox.BeginUpdate(); foreach (string item in items) { listBox.Items.Add(item); } listBox.EndUpdate(); }