在ComboBox中慢速滚动 [英] Slow scrolling in ComboBox

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

问题描述

我有一个问题,其中滚动在一个toolStripComboBox和常规ComboBox是真的很慢。



这种情况都发生在使用arrowkeys和鼠标滚轮。



这里是工具条组合框:

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



和常规组合框:

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

有没有人遇到过这个问题?

> 更改SelectionChangeCommitted的事件处理程序解决了关于箭头键而不是鼠标部分的问题。



鼠标滚动行为只有当鼠标在下拉列表上时才会异常。



编辑2


$ b如果没有移动鼠标并点击滚轮, $ b

想象出鼠标滚动的问题,原来是联想鼠标套件软件和/或驱动程序。



感谢Jeff Yates向我展示SelectionChangeCommitted事件。

解决方案

使用键盘时,所选索引更改。使用滚轮时,鼠标更改下的项目也会导致 SelectedIndexChanged 事件。
因此,如果你的事件处理程序在索引改变时是密集的,它将减慢滚动速度,因为每次所选的索引改变时(即每次用鼠标或键盘滚动),滚动都会运行。您应该使用 SelectionChangeCommitted 处理



更新
那么,您的当组合不下降时使用鼠标滚轮?如果是这种情况,则仍然是选择改变处理,因为每个滚轮将改变提交的选择。



我建议您使用计时器添加某种选择过滤器。每次提交选择时,启动(并重新启动)计时器。只有当定时器触发时,你实际上处理选择更改。这样,您就可以使用鼠标滚轮滚动,而不会每次都导致选择惩罚。当然,当它触发时,请务必停止计时器。


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.

解决方案

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.

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

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