【问题标题】:.NET c# avoid selectedIndex event when populating ComboBox.NET c# 在填充 ComboBox 时避免 selectedIndex 事件
【发布时间】:2016-10-15 01:28:59
【问题描述】:

我在加载 ComboBox 时遇到了一点问题。

问题是在加载数据的阶段,默认的selectedIndex事件会触发。

如何在加载过程中防止这种情况发生?

【问题讨论】:

标签: c# .net


【解决方案1】:

我建议使用全局变量

Boolean isLoaded = false;

在您的 selectedIndexChange 中添加此代码

if(!isLoaded)
{
isLoaded = true;
}
else
{
 /// write your code here 
}

【讨论】:

    【解决方案2】:

    我会删除该事件并在数据加载完成后重新添加它。

        combo.SelectedIndexChanged -= combo_SelectedIndexChanged;
        //Do the loading of the data into the combo
        combo.SelectedIndexChanged += new EventHandler(combo_SelectedIndexChanged);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 2014-06-20
      相关资源
      最近更新 更多