Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the old selected index in Winform's Combo box

I have a combo box (winform). This combo box has some items (eg. 1,2,3,4).

Now, when I change the selection within this combo, I wish to know the old index and the new index.

How do I get this?

Possible approaches that I wish to AVOID.

  1. Add an enter event, cache the current index and then on selection index change get the new index.

  2. Using the selected text/selected item property received by the sender of the event.

What I ideally want:

  1. In the event args that are received, I want something like:

    e.OldIndex; e.newIndex;

    Right now the event args which are received in the SelectionIndex Change event are totally useless.

  2. I don't want to use more than one event.

  3. If C#, does not offer this, can I have my event which passes the old index and new index as event args?

like image 928
Nikhil Avatar asked Aug 23 '12 08:08

Nikhil


1 Answers

Seems like this is a possible duplicate

ComboBox SelectedIndexChanged event: how to get the previously selected index?

There is nothing built in, you will need to listen for this event and keep track in a class variable.

But this answer seems to suggest a sensible way of extending the combobox to keep track of the previous index https://stackoverflow.com/a/425323/81053

like image 65
Chris Moutray Avatar answered Sep 30 '22 18:09

Chris Moutray