Sesame
Sesame

Reputation: 3410

Retrieve value of most recently SelectedItem from multi-select listbox

How can I retrieve the value of a clicked item in a multi-select listbox?

Currently, if I click one item and use lstBox.SelectedValue, it will return the proper value; however, if I then click on another item, I am still shown the first item's value.

Basically, I want the value of the item most recently clicked on, regardless of whether or not it is the SelectedValue.

Upvotes: 0

Views: 1511

Answers (2)

itsmatt
itsmatt

Reputation: 31406

The SelectedIndexChanged handler will get called when you select/unselect an item in the listbox.

However, it doesn't indicate which one was selected/unselected.

listbox1.SelectedItems

will contain the currently selected items and you could internally keep track of which index was most recently added.

Upvotes: 1

Colin Pickard
Colin Pickard

Reputation: 46643

If it is a multiple selection listbox, you can get a collection of all the selected items by using SelectedItems instead of SelectedItem.

If you need to know the sequence in which the items were selected, or which was selected most recently, I think you would need to record if yourself by SelectedIndexChanged event.

Upvotes: 1

Related Questions