drag & drop list box items 
Author Message
 drag & drop list box items

I want to drag items from a list box and copy them to other list boxes.
When the drag property is set to automatic the whole list box drags,
rather than the selected item from the list.  How can this be corrected?

Joe



Wed, 16 Oct 2002 03:00:00 GMT  
 drag & drop list box items
The way to get round the problem with the whole list being dragged is to set
the DragIcon property for the listbox to a relevant image. If you don't set
the DragIcon property for a control, windows defaults to an outline
rectangle which is the same size as the control that has the drag operation.
Also you may want to set the DragMode to Manual because otherwise it may
cause some problems when you are trying to just select list items.

If the DragMode is set to Manual, you need to tell it when to drag the item.
This is done by testing the MouseMove event for the list box. You need to
check if the button is down (normally the left) and then tell it to drag if
that's the case.

Try the following example. Put two list boxes on a form, List1 and List2.
Set the DragIcon property of List1 to any image (there are some images in
the graphics directory with the VB directory). Make sure that the DragMode
of List1 is set to Manual. Now put in the following code:

Private Sub Form_Load()
    ' Load some items into the list
    List1.AddItem "Item1"
    List1.AddItem "Another Item"
    List1.AddItem "The Third Item"
End Sub

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
    ' Test whether the left mouse button is pressed
    If Button = 1 then
        ' Now set it to drag
        List1.Drag
    End If
End Sub

Public Sub List2_DragDrop(Source As Control, X As Single, Y As Single)
    ' This occurs when the user drops the List1 Item into List2
    ' We need to add the dragged item to List2
    List2.AddItem List1.List(List1.ListIndex)
    ' The following line will remove the item from List1
    List1.RemoveItem List1.ListIndex
End Sub

Anyway, I hope this helps you

Wayne

Quote:

> I want to drag items from a list box and copy them to other list boxes.
> When the drag property is set to automatic the whole list box drags,
> rather than the selected item from the list.  How can this be corrected?

> Joe



Wed, 16 Oct 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Drag and Drop on Individual items within list boxes

2. Drag-drop reorder of list box items

3. Reordering a list box with drag & drop

4. Help in understanding drag drop from a list box to a rich text box

5. How to drag-drop MultiSelect list items?

6. Drag&Drop of an Outlook Item

7. Dragging and Dropping List Box context

8. drag and dropping into a directory list box

9. Drag and Drop in a List Box

10. Drag and Drop in List Box in VB

11. 4.0 list box drag drop error driving me nuts

12. Drag and drop from Outlook to file list box

 

 
Powered by phpBB® Forum Software