0

Suppose I have a ComboBox and I want to get a previous value of the ComboBox just before it changes to the new selected index.

In a TextBox for example I can get it by using KeyDown of keyevents to get previous value but cant figure out what to do in a ComboBox.

I tried using dropdown event but it went on to call my SelectedIndexChange method of the ComboBox as and when dropdown event was being was called , which I don't want.

Could anyone please help me?

Ian R. O'Brien
  • 6,682
  • 9
  • 45
  • 73
Brij123
  • 73
  • 2
  • 9
  • Possible duplicate : http://stackoverflow.com/questions/4801831/how-to-get-the-previous-item-on-dropdownlist-before-onselectedindexchanged-fires – Jason Evans Feb 22 '13 at 17:54
  • Possible duplicate: or here http://stackoverflow.com/questions/11496860/getting-previous-value-of-the-combobox – DJ Burb Feb 22 '13 at 17:54

1 Answers1

0

You could use something like this.

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;
}

All you need to do is set SelectedIndexChangedevent on cmbBox1.

Neeraj Kumar
  • 771
  • 2
  • 16
  • 37
Daniel Wardin
  • 1,840
  • 26
  • 48