0

I'm trying to get a combobox in winform that has around 5'000 entries. I've run into a problem before - addrange hangs with this many entries. I created a seperate control to do this for myself without lagging, but I'm adding this functionality to existing comboboxes.

I was looking up VirtualizingStackPanel for WPF when trying to see if I could get around this.

Is there a way to improve the performance of addrange for a couple of thousand string entries?

Charles
  • 548
  • 1
  • 7
  • 25
  • Are you sure that a combobox is the right interface element to represent 5000 entries? I think this is not ideal for the user. – Oliver Sep 10 '12 at 15:14
  • It is in this case : The program has been running this way since the start and they're very used to it. I am curious what others would use instead of a combobox? Listbox, etc. – Charles Sep 10 '12 at 15:15
  • 2
    As a user I would prefer a textbox with some kind of autocomplete.. – Matt Sep 10 '12 at 15:18
  • 2
    Or better yet: a textbox with a button that opens a new resizable window that has all the items in, with find-as-you-type substring item elimination. – Dai Sep 10 '12 at 15:19
  • I need to demand my job give me a better computer to program in then a 5 year old half broken laptop so I don't miss that my code is running inside a for loop. On a side note, dear god did I improve the effeciency of that program since I thought that wasn't the bottleneck >. – Charles Sep 10 '12 at 15:39
  • One of my computers is 8 years old and works perfectly fine for coding on (Athlon64 3200, 4GB RAM, GeForce 6800GT). I don't buy your excuses :) – Dai Sep 10 '12 at 16:08
  • You also don't have autocad, a few image and video manipulation hardwares, VS and a few other things running in tandem >.> I'm a total resource hog ^.^;;;; It was also a lapse on my behalf, I just got use to R#'s ending tags and they've stopped working recently. – Charles Sep 10 '12 at 16:47

1 Answers1

4

Have you tried using ComboBox.BeginUpdate and ComboxBox.EndUpdate? Using those methods improves performance when adding items.

Of course, if you have 5000 items then maybe using a ComboBox isn't the right control (having more than 200 items or so makes scrolling impossible, which defeats the point of having a drop-down selector). Have you considered using a normal textbox but with an autocomplete provider instead?

Dai
  • 141,631
  • 28
  • 261
  • 374
  • +1 for the second paragraph. As for the first, don't expect any gains from `BeginUpdate` and `EndUpdate` if you are already using `AddRange`. – Rotem Sep 10 '12 at 15:18
  • +1 for the first paragraph. BeginUpdate and EndUpdate helped me a lot with performance problems I have had with adding a lot of controls to forms. – Kuba Sep 10 '12 at 15:27