I seem to be having trouble programmatically changing the SelectedIndex of a listbox after a Drag/Drop has completed.
I have a source listbox and a target listbox. I click the left mouse button over an item in the source, hold the button down, then drag to the target and release. The code to handle the drag/drop is successful.
The weird part comes when I try to set the SelectedIndex to -1 after the drag/drop has completed. This line comes at the end of the DragDrop event in the target listbox. This is to clear out the highlighted selection in the source listbox instead of leaving it selected.
After doing some stepping, I've noticed the very first drag/drop will fire the SelectedIndexChanged event right before the DragDrop event on the target listbox. However, the index is -1 even though something was selected. After any subsequent drag/drops, the SelectedIndexChanged event will not fire. Programmatically changing the SelectedIndex to -1 will not work. Even though I step over the statement, the index remains at whatever was selected. I even made a debug button that just sets the SelectedIndex to -1 and I also tried ClearSelected.
I actually have to just click on the source listbox (no drag/drop), then the drag/drop right after that will work. More than one will not work.
Any idea what is going on?
I have a source listbox and a target listbox. I click the left mouse button over an item in the source, hold the button down, then drag to the target and release. The code to handle the drag/drop is successful.
The weird part comes when I try to set the SelectedIndex to -1 after the drag/drop has completed. This line comes at the end of the DragDrop event in the target listbox. This is to clear out the highlighted selection in the source listbox instead of leaving it selected.
After doing some stepping, I've noticed the very first drag/drop will fire the SelectedIndexChanged event right before the DragDrop event on the target listbox. However, the index is -1 even though something was selected. After any subsequent drag/drops, the SelectedIndexChanged event will not fire. Programmatically changing the SelectedIndex to -1 will not work. Even though I step over the statement, the index remains at whatever was selected. I even made a debug button that just sets the SelectedIndex to -1 and I also tried ClearSelected.
I actually have to just click on the source listbox (no drag/drop), then the drag/drop right after that will work. More than one will not work.
Any idea what is going on?