views:

1103

answers:

1

Hi,

I have a problem where scrolling in both a toolStripComboBox and regular ComboBox is really slow.

This happens both using the arrowkeys and the mouse scrollwheel. However, if I use the scrollbar it behaves as expected.

Here's the toolstrip combobox:

        // 
        // toolStripComboBoxDeild
        // 
        this.toolStripComboBoxDeild.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
        this.toolStripComboBoxDeild.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
        this.toolStripComboBoxDeild.DropDownWidth = 121;
        this.toolStripComboBoxDeild.Items.AddRange(new object[] {
        "Allir"});
        this.toolStripComboBoxDeild.Margin = new System.Windows.Forms.Padding(1, 0, 8, 0);
        this.toolStripComboBoxDeild.MaxDropDownItems = 24;
        this.toolStripComboBoxDeild.Name = "toolStripComboBoxDeild";
        this.toolStripComboBoxDeild.Size = new System.Drawing.Size(200, 52);
        this.toolStripComboBoxDeild.SelectedIndexChanged += new System.EventHandler(this.toolStripComboBoxDeild_SelectedIndexChanged);

I'm adding the rest of the data in the combobox with an SqlDataReader (not using a dataset because I'm comfortable using the sqlreader).

and the regular combobox:

// 
        // comboBox1
        // 
        this.comboBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
        this.comboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
        this.comboBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.comboBox1.FormattingEnabled = true;
        this.comboBox1.Location = new System.Drawing.Point(77, 17);
        this.comboBox1.Name = "comboBox1";
        this.comboBox1.Size = new System.Drawing.Size(221, 21);
        this.comboBox1.TabIndex = 1;
        this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);

Has anyone ever run into this problem? If so, what did you do to solve it?

EDIT

Changing the event handler to SelectionChangeCommitted solved the problem regarding the arrow keys, but not the mouse part.

The mouse scrolling behaviour is only aberrant when the mouse is over the dropdown list. When I click the combobox down arrow without moving the mouse and apply the scroll wheel, the list scrolls as expected.

EDIT 2

Figured out the problem with the mouse scrolling, turns out that it's the "Lenovo Mouse Suite" software and/or driver. Uninstalled it and now everythings just fine.

Thanks to Jeff Yates for showing me the SelectionChangeCommitted event.

+3  A: 

When you use the keyboard, the selected index changes. When using the scroll wheel, the item under the mouse changes which will also lead to the SelectedIndexChanged event. Therefore, if your event handler is intensive when the index changes, it will slow down the scrolling as it will run each time the selected index changes (i.e. each time your scroll with the mouse or keyboard). You should use SelectionChangeCommitted to handle when the selection changes instead as this will only fire once the combo is closed.

Update
So, you use the mouse wheel when the combo is NOT dropped down? If that is the case, then it is still the selection change handling as each roll of the wheel will change the committed selection. Scrolling when the combo is dropped down does not do this.

I recommend you add some kind of selection filter using a timer. You start (and restart) the timer each time the selection is committed. Only when the timer fires do you actually handle the selection change. This way, you scroll with the mouse wheel without incurring a selection penalty each time. Make sure to stop the timer when it fires, of course.

Jeff Yates
Hi Jeff, thanks for your input.I tried your suggestion, but the problem is still there. Do you have any other insights?Again, thanks for your help
Johann J.
Hmm, well, have you tried it without any selection change event to see if that is where the issue lies at all?
Jeff Yates
Tried it again (more carefully) and can confirm that SelectionChangeCommitted cured the scrolling with arrowkey problem. Check the edited question to see how it is when scrolling with the mousewheel
Johann J.
I would still expect selection is something to do with this as that would explain why it only happens when the mouse is over the list. Interesting.
Jeff Yates
I just wish it would stop being interesting and go away :)
Johann J.
No, the combo is dropped down, but I don't move the mouse from the dropdown arrow, just scroll in place. I'll think about the timer idea.
Johann J.
I still think that it is the selection commit event firing (a breakpoint or trace will confirm it).
Jeff Yates
The mousewheel is not firing the commit event. But I've figured out what the problem is. It's the Lenovo Mouse Suite and/or drivers. Uninstalled and now everythings fine.
Johann J.
Excellent! I'm glad you managed to fix that final part. Thanks for sharing the result too.
Jeff Yates