I don’t know if the title express what I want. I have a ListBox in WPF where I generate many elements. When I click on a element while still generating I want my selected item to not move down the list, so I cannot see it anymore, I want to stay in the exact position where I click on it.
If this is possible, can someone point some ideas on how to do it in C#?
Thanks.
Assuming that this is even a good idea and that you are using winforms
Step 1:
Determine the index of the selected item in the source.
Step 2:
When your adding items to the
ListBoxsplit theListBoxat the index where the item previously was insert the item at that point, then add on the remainder of the items, while making sure that you’ve removed the item if it is now elsewhere in the list.Code:
//Let’s assume that you know how to get the position of the item when it is clicked and save the
//item to a variable called OriginalItem
Saw your edit about it being WPF
The could should work in idea.