2015-03-13 24 views
0

考慮一個非常基本的形式用一個簡單的組合框簡單組合框 - 射擊兩次(使用鼠標擴大組合框,並使用鍵盤選擇項)

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
     this.comboBox1.Items.Add("test1"); 
     this.comboBox1.Items.Add("test2"); 
     this.comboBox1.Items.Add("test3"); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     this.comboBox1.SelectedIndexChanged += (o, args) => 
     { 
      MessageBox.Show("Combo box changed!"); 
     }; 
    } 
} 

我甚至改變了事件處理程序,以下面的代碼。 (上鍊接的問題爲主。還是同樣的問題)

this.comboBox1.SelectedValueChanged += (o, args) => //or even `Textchanged` event too 
      { 

       MessageBox.Show("Combo box changed!"); 
      }; 

展開使用mouse下拉列表並使用keyboard選擇任何項目。

組合框中閃光兩次(出現消息框兩次)

任何想法,爲什麼?

+2

使用'Debug.Print',而不是消息框進行調試。的 – i486 2015-03-13 09:12:31

+0

可能重複[捕取消選擇所有的ListView - 射擊的SelectedIndexChanged兩次(http://stackoverflow.com/questions/5740756/catching-unselecting-all-in-listview-selectedindexchanged-firing-twice) – Sayse 2015-03-13 09:13:25

+0

你有什麼其他代碼初始化了這個事件?即在designer.cs中 – 2015-03-13 09:14:21

回答

0

看起來像這是基礎框架的錯誤。

所以,我設法解決了這個問題。

方法如下:

  1. 有一個私有變量(最好),它可以選擇的項目的值存儲在組合框中
  2. 下一次,它在combo-當前選擇比較框。如果它們一樣,就回來。
相關問題