views:

22

answers:

1

Scenario:

  • Windows Form
  • Listbox
  • SelectionMode = MultiSimple
  • Items 1 and 5 are selected already
  • User selects item 3 by clicking on it or by pressing the spacebar after it has focus

Q: How do I get its index or value on SelectionChanged? I.e., how do I know which item was just selected (or de-selected)? FYI, SelectedItem will return item 1 (i.e., the item at index 0 in the SelectedItems collection).

+1  A: 

You want to use SelectedItems, it will tell you all of the items that are selected.

In terms of knowing with item was just selected, you might have to remember what the old SelectedItems are, and compare to the new SelectedItems.

You can also check the EventArgs of the SelectionChanged event, however, I don't think it gives you that information.

mlsteeves