How to get the last selected item in a .Net Forms multiselect ListBox? Apparently if I select an item in the listbox and then select another 10 the selected item is the first one.
I would like to obtain the last element that I selected/deselected.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would take this general approach:
Listen for the
SelectedIndexChangedevent and scan through theSelectedIndicescollection every time.Keep a separate list of all selected indices, appending ones that have not been in the list, removing those that have been de-selected.
The separate list will contain the indexes in the chronological order they were selected by the user. The last element always is the most recently selected index.