避免 N2 迭代
它放在 Windows 窗體事件處理程式中
var nameList = new BindingList<string>();
ComboBox1.DataSource = nameList;
for(long i = 0; i < 10000; i++ ) {
nameList.AddRange(new [] {"Alice", "Bob", "Carol" });
}
這需要很長時間來執行,修復,執行以下操作:
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();