2013-02-22 65 views
0

假设我有一个ComboBox,并且我希望在其更改为新选定索引之前获得ComboBox的先前值。如何在selectedindexchange方法之前获取组合框的当前值?

TextBox比如我可以用的KeyEvents的KeyDown获得前值得到它,但无法弄清楚如何在ComboBox做。

我试过使用dropdown事件,但它继续调用ComboBoxSelectedIndexChange方法,当调用dropdown事件时,我不想这样做。

任何人都可以帮我吗?

+0

可能的重复:http://stackoverflow.com/questions/4801831/how-to-get-the-previous-item-on-dropdownlist-before-onselectedindexchanged-fires – 2013-02-22 17:54:29

+0

可能的重复:或这里http:// stackoverflow .com /问题/ 11496860 /越来越先前价值的组合框 – 2013-02-22 17:54:49

回答

0

你可以使用这样的东西。

public Form1() 
{ 
    InitializeComponent(); 
    cmbBox1.Tag = cmbBox1.SelectedIndex; 
} 

private void cmbBox1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    lblPrevState.Text = cmbBox1.Tag.ToString(); // Just store the value of to a variable or do whatever you need to do with it here - each time it calls tag will contain previous index value 
    cmbBox1.Tag = cmbBox1.SelectedIndex; 
} 

您需要做的就是在cmbBox1上设置SelectedIndexChangedevent。

希望它有帮助。

+0

嘿,我不明白我将如何使用它的组合框...你可以建议吗? – Brij123 2013-02-22 18:12:41

+0

对不起missread combobox as checkbox,将现在的例子更改为combobox – 2013-02-22 21:41:02

+0

在这里你去,这里是代码combobox,相同的原理 – 2013-02-22 21:44:55