   [.net] ListBox.SelectedIndex troubles
  I have a listbox with it's selection mode set to multiextended.  What I'm doing is catching the indexchanged event and displaying an image in a picturebox control.  The problem I'm coming across is when multiple items are selected in the listbox.  It seems that when the index is changed, even with multiple indices selected, the selectedindex contains the smallest index (i.e. if I select item at index 0 and then select item at index 5, selectedindex contains index 0).  I know that there is also a selectedindices method, but I'm coming across the problem of finding out which was the last selected index.  Basically, I would like my picturebox control to display the image in the last index selected.  How would I go about doing something like this?   
  Well, I couldn't find a ready solution in MSDN. So if you want you could do this:Keep an array of all the selected indices.Everytime that event is fired, you loop through your array and check it against the SelectedIndices of the listbox, and display the picture of whichever index is not in your array, then add that index to your array.;  Is there a reason the selection mode is multi if you're only displaying a graphic for one item? My recommendation - change the selection mode to single.   ;  For the most part, users would be selecting items singly.  However, items from the listbox can be deleted.  Selecting multiple items works faster for deleting, but that's where the problem lies.  Basically, when the user selects items for deletion, I'd like them to be able to see what the last item they selected was.Have a couple friends testing out the program though.  One had no comment on it, the other said he preferred single selecting to delete the item.  If I can't get this problem solved, I'll set it to single select.   ;  You could have the program only display something if a single item is selected and assuming the user is in "delete" mode if multiple items are selected.   ;  The thing to understand here is the distinction between the SelectedIndex Property and the SelectedIndicies Property.SelectedIndex is an integer data type suitable for when Multiselect is off. SelectedIndices is a SelectedIndexCollection suitable for use when Multiselect is on.If you plan on using some form of multiselect, you'll want to use SelectedIndicies.Edit:If you want to know what the most recently selected item in the list was, you should be able to use one of the Click events. (Click or one of the mouse event, MouseDown, etc.) The trouble is using the mouse events will not capture keyboard input.A better solution: use the ListView (System.Windows.Forms.ListView) control. Its index properties seem easier to use to me. To be honest the ListBox feels like a lightweight version of the ListView. If ListBox doesn't do what you want chances are the ListView will.Failing that, you could continue to use the listBox by creating a copy of SelectedIndicies in memmory, and comparing against it to find what changed, but that feels like an ugly hack if you can get the information you want from one of the click events.Second Edit:the listview control also allows items to have an Icon which you could set to a small version of the graphic that would otherwise be displayed. This would give users another visual clue as to what a given item is.[Edited by - zangetsu on June 20, 2006 11:24:10 AM]