birdus
birdus

Reputation: 7504

Get most recently selected item (WinForms)

Scenario:

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).

Upvotes: 0

Views: 166

Answers (1)

mlsteeves
mlsteeves

Reputation: 1271

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.

Upvotes: 1

Related Questions