Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharpNotesForProfessionals.pdf
Скачиваний:
65
Добавлен:
20.05.2023
Размер:
6.12 Mб
Скачать

Chapter 92: BindingList<T>

Section 92.1: Add item to list

BindingList<string> listOfUIItems = new BindingList<string>(); listOfUIItems.Add("Alice");

listOfUIItems.Add("Bob");

Section 92.2: Avoiding N*2 iteration

This is placed in a Windows Forms event handler

var nameList = new BindingList<string>(); ComboBox1.DataSource = nameList; for(long i = 0; i < 10000; i++ ) {

nameList.AddRange(new [] {"Alice", "Bob", "Carol" });

}

This takes a long time to execute, to fix, do the below:

var nameList = new BindingList<string>(); ComboBox1.DataSource = nameList; nameList.RaiseListChangedEvents = false; for(long i = 0; i < 10000; i++ ) {

nameList.AddRange(new [] {"Alice", "Bob", "Carol" });

}

nameList.RaiseListChangedEvents = true; nameList.ResetBindings();

GoalKicker.com – C# Notes for Professionals

507