I'm making a program where I have to compare any 2 selected objects from a ListBox. This is what I'm trying to do:
object figure1 = lstFiguras.SelectedItem;
object figure2 = lstFiguras.SelectedItem;
What I want to happen is that the user highlights 2 seleccions from the ListBox. I want figure1 to be assigned the first selection, and figure2 to be assigned the second seleccion, but I can't seem to find a property or workaround that lets this happen. One ListBox only lets me use one SelectedItem. Is there a workaround of sorts I can use?
Image not related, aside from being a listbox.
Might help if you told us what language you were working with.
>>291652
Of course, sorry, it's C#. Only language I've used. I assumed a Windows Form would have the same code for any language.
>>291656
>One ListBox only lets me use one SelectedItem.
Have you tried this?
If you have, then you could try using somekind of Do{} While()
>>291680
Sorry, I didn't explain myself very well.
I already have it set so that multiple items can be selected from the ListBox. The problem is, after I highlight 2 different items, I want them assigned to different variables.
In your picture, for example, after selecting 1 and 4, I want 1 to be assigned to VariableOne, and the 4 to be assigned to VariableTwo.
>>291656
>>291680
The code should be something like this.
>>291686
Well you can follow this code:
>>291687
just add an array to save the values of the selected items in the listbox. Something like this.
>>291690
And of course, add an exception to avoid the user to select more than 2 items from the listbox.
>>291690
Well, butter my backside and call me a biscuit, this did it. I've got an exam in 7 hours and you may have just saved the day. Thanks very much, anon. (And to the other anon, too!)