【问题标题】:Slow scrolling in ComboBoxComboBox 中的慢速滚动
【发布时间】:2009-04-20 14:23:57
【问题描述】:

我有一个问题,即在 toolStripComboBox 和常规 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);

我正在使用 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

找出鼠标滚动的问题,原来是“联想鼠标套件”软件和/或驱动程序。卸载它,现在一切正常。

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

【问题讨论】:

    标签: c# winforms combobox scroll


    【解决方案1】:

    当您使用键盘时,selected index changes。使用滚轮时,鼠标下的项目会发生变化,这也会导致SelectedIndexChanged 事件。 因此,如果您的事件处理程序在索引更改时是密集的,它将减慢滚动速度,因为它会在每次选定的索引更改时运行(即每次使用鼠标或键盘滚动时)。您应该使用SelectionChangeCommitted 来处理选择更改时,因为这只会在组合关闭后触发。

    更新
    那么,当组合没有被下拉时,您使用鼠标滚轮吗?如果是这种情况,那么它仍然是选择更改处理,因为轮子的每次滚动都会更改提交的选择。下拉组合时滚动不会执行此操作。

    我建议您使用计时器添加某种选择过滤器。每次提交选择时,您都会启动(并重新启动)计时器。只有当计时器触发时,您才会真正处理选择更改。这样,您可以使用鼠标滚轮滚动,而不会每次都产生选择惩罚。当然,请确保在计时器触发时停止计时器。

    【讨论】:

    • 嗨,杰夫,感谢您的意见。我尝试了你的建议,但问题仍然存在。您还有其他见解吗?再次感谢您的帮助
    • 嗯,你有没有试过没有任何选择更改事件,看看这是否是问题所在?
    • 再次尝试(更仔细)并可以确认 SelectionChangeCommitted 解决了箭头键滚动问题。检查编辑的问题,看看使用鼠标滚轮滚动时的情况
    • 我仍然希望选择与此有关,因为这可以解释为什么它仅在鼠标悬停在列表上时才会发生。很有趣。
    • 鼠标滚轮没有触发提交事件。但我已经弄清楚了问题所在。这是联想鼠标套件和/或驱动程序。已卸载,现在一切正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    • 2011-08-01
    • 2012-06-22
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 2015-10-09
    相关资源
    最近更新 更多