在组合框滚动缓慢 [英] Slow scrolling in ComboBox

查看:255
本文介绍了在组合框滚动缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,即在既有ToolStripComboBox控件滚动和定期的ComboBox实在是太慢了。

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

这两种情况使用arrowkeys和鼠标滚轮。但是,如果我使用滚动条,其行为预期的

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

下面是工具条组合框:

        // 
        // 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);



我添加在下拉列表中的数据的其余部分与SqlDataReader的(不使用的数据集,因为我很舒服的使用SQLReader的)

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).

和常规组合框:

// 
        // 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?

更改事件处理程序SelectionChangeCommitted解决有关箭头键的问题,但不是鼠标的一部分。

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.

想通了这个问题用鼠标滚动,原来,它的联想鼠标套件软件和/或驱动程序。卸载它,现在万物就好了。

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.

感谢杰夫·耶茨为我展示SelectionChangeCommitted事件。

Thanks to Jeff Yates for showing me the SelectionChangeCommitted event.

推荐答案

在使用键盘时,的选定的索引更改。当使用滚轮,下鼠标的变化项目这也将导致在的SelectedIndexChanged 事件。
因此,如果你的事件处理程序是密集的当指数的变化,它会减慢滚动,因为它会在每次选择的指数的变化(即每次您的滚动鼠标或键盘)运行。您应该使用 SelectionChangeCommitted 处理时选择的变化,而不是因为这只会火一旦组合被关闭。

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.

这篇关于在组合框滚动缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆