Performance ComboBox.Items.AddRange

I have a ComboBox, which when I re-fill it seems to take quite a while. After some profiling, I found that most of the time is spent in the ComboBox.Items.AddRange (Array) method. I have included the example method below, which shows how I am refilling the ComboBox.

public void Repopulate(IList<MyType> sortedList)
{
    MyComboBox.BeginUpdate();

    try
    {
        MyComboBox.Items.Clear();
        MyComboBox.Items.AddRange(sortedList.ToArray());
    }
    finally
    {
        MyComboBox.EndUpdate();
    }
}

sortedList 280 , 53 ComboBox, . , , ( 700 , 8000 ), . sortedList IList, 1 ( ).

ComboBox, , , IList, . .

- , , ComboBox?

+3
4

, combobox Sorted. AddRange, combobox , , , .

, , 10000 AddRange. , combobox Sorted, - . AddRange

notSortedCombo: 5ms
sortedCombo: 1140ms

? 53 comboboxes, ?

+1

AddRange BeginUpdate EndUpdate , , .

:

public void Repopulate(IList<string> sortedList) {
  comboBox1.BeginUpdate();
  comboBox1.Items.Clear();
  foreach (string item in sortedList) {
    comboBox1.Items.Add(item);
  }
  comboBox1.EndUpdate();
}

, , : 53 - - 53 . (1 ), , .

. .

+1

: WPF (Example) WinForms. , ListView, DataGridView, TreeView .. , . , .

? , .

. / .NET, . , combobox combobox ( TPL). , .

- , ComboBox. , ComboBox.

, . (fooobar.com/questions/38742/...). , .

0

, FormattingEnabled False

, Visual Studio True, "" , .

,

0

All Articles