Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot programmatically change Listbox SelectedIndex after Drag/Drop

Status
Not open for further replies.

Sypher2

Programmer
Oct 3, 2001
160
US
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?
 
Not tested, but you can try it:

Refresh the listbox and then set the .selectedindex to -1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top