Drag and drop between listboxes with multiple selection

titanovics

Newcomer
Joined
Apr 12, 2003
Messages
2
I need to implement drag and drop between two listboxes with multiple selection. In order to achieve that I handle the MouseMove, DragOver and DragDrop events for both.
The problem is that when I click on an (unselected) item in one listbox, hold down the left mouse button and drag the item to the other one the item is not dropped in the latter. I managed to figure out that the problem occurs in the MouseMove event handler. Here is its code:

C#:
if (e.Button == MouseButtons.Left)
{
         int nSelItemsCount = listBox2.SelectedItems.Count;
         /* In the case described above nSelItemsCount is not 0.
         */
         if (nSelItemsCount > 0)
         {
                   listBox2IsDropSource = true;
                   if (listBox2.DoDragDrop(listBox2.SelectedItems,    
                       DragDropEffects.All) == DragDropEffects.Move)
                  {
                       ArrayList list = new ArrayList();
                       /* In the case described above the SelectedItems 
                        * collection seems to be empty even if its Count
                        * property is not 0.
                       */
                       foreach (object o in listBox2.SelectedItems)
                       {
                                  /* In the case described above
                                   * this part of the code is never reached.
                                  */

                                  list.Add(o);
                       }
                       foreach (object o in list)
                       {
                                  listBox2.Items.Remove(o);
                       }
                       listBox2IsDropSource = false;
                 }
         }
}

As I mentioned in the comments, the SelectedItems collection
seems to be empty even if its Count property differs from 0.
In all other cases the drag and drop works fine.
Any help would be greatly appreciated.
 
Last edited by a moderator:
It would be easier to read you code if you enclose it with:
Code:
[code] and end with
[/code]
or the c# equivalent. Whatever that is. If anyone knows what the c# equivalent is please let me know.
 
Back
Top