3
votes

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.

1

1 Answers

3
votes

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.