How to drag and drop within same Listbox 
Author Message
 How to drag and drop within same Listbox

Will anyone share with me some code that allows dragging and dropping
with in the same listbox so a user can reoder the list?

TIA,

Robin



Thu, 19 Apr 2001 03:00:00 GMT  
 How to drag and drop within same Listbox

Quote:

> Will anyone share with me some code that allows dragging and dropping
> with in the same listbox so a user can reoder the list?

> TIA,

> Robin

Try this....

Option Explicit
Dim DragEnable As Boolean
Dim DragInProgress As Boolean
Dim DragIndex As Long

Private Sub Form_Load()
Dim i
    For i = 0 To 8
    List1.AddItem "Line " & CStr(i)
    Next
End Sub

Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    DragEnable = True
    DragIndex = List1.ListIndex
End Sub

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If DragEnable Then
    If Button = 1 Then
        List1.MousePointer = 7
        DragInProgress = True
        DragEnable = False
    End If
End If

End Sub

Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim tmpIndex, tmpItem$

    If DragInProgress Then
       tmpIndex = List1.ListIndex
       If tmpIndex <> DragIndex Then
          tmpItem = List1.List(DragIndex)
          List1.RemoveItem DragIndex
          List1.AddItem tmpItem, tmpIndex
          List1.ListIndex = List1.NewIndex
       End If
       List1.MousePointer = 0
       DragInProgress = False
       DragEnable = False
    End If

End Sub

LFS



Thu, 19 Apr 2001 03:00:00 GMT  
 How to drag and drop within same Listbox
Thanks Larry :)

Best,

Robin

Quote:


> > Will anyone share with me some code that allows dragging and dropping
> > with in the same listbox so a user can reoder the list?

> > TIA,

> > Robin

> Try this....

> Option Explicit
> Dim DragEnable As Boolean
> Dim DragInProgress As Boolean
> Dim DragIndex As Long

> Private Sub Form_Load()
> Dim i
>     For i = 0 To 8
>     List1.AddItem "Line " & CStr(i)
>     Next
> End Sub

> Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
>     DragEnable = True
>     DragIndex = List1.ListIndex
> End Sub

> Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
> If DragEnable Then
>     If Button = 1 Then
>         List1.MousePointer = 7
>         DragInProgress = True
>         DragEnable = False
>     End If
> End If

> End Sub

> Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
> Dim tmpIndex, tmpItem$

>     If DragInProgress Then
>        tmpIndex = List1.ListIndex
>        If tmpIndex <> DragIndex Then
>           tmpItem = List1.List(DragIndex)
>           List1.RemoveItem DragIndex
>           List1.AddItem tmpItem, tmpIndex
>           List1.ListIndex = List1.NewIndex
>        End If
>        List1.MousePointer = 0
>        DragInProgress = False
>        DragEnable = False
>     End If

> End Sub

> LFS



Thu, 19 Apr 2001 03:00:00 GMT  
 How to drag and drop within same Listbox
Would it be possible to do  that in a ListView control also?

Thanks :)

--
Ricky
ICQ# 4730537             EGN# 16191
kharjes at dgi dot net
http://www.geocities.com/~howdy
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Please Reply To The Newsgroups

Quote:

>Thanks Larry :)

>Best,

>Robin



>> > Will anyone share with me some code that allows dragging and dropping
>> > with in the same listbox so a user can reoder the list?

>> > TIA,

>> > Robin

>> Try this....

>> Option Explicit
>> Dim DragEnable As Boolean
>> Dim DragInProgress As Boolean
>> Dim DragIndex As Long

>> Private Sub Form_Load()
>> Dim i
>>     For i = 0 To 8
>>     List1.AddItem "Line " & CStr(i)
>>     Next
>> End Sub

>> Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As

Single, Y As Single)
Quote:
>>     DragEnable = True
>>     DragIndex = List1.ListIndex
>> End Sub

>> Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As

Single, Y As Single)
Quote:
>> If DragEnable Then
>>     If Button = 1 Then
>>         List1.MousePointer = 7
>>         DragInProgress = True
>>         DragEnable = False
>>     End If
>> End If

>> End Sub

>> Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As

Single, Y As Single)

- Show quoted text -

Quote:
>> Dim tmpIndex, tmpItem$

>>     If DragInProgress Then
>>        tmpIndex = List1.ListIndex
>>        If tmpIndex <> DragIndex Then
>>           tmpItem = List1.List(DragIndex)
>>           List1.RemoveItem DragIndex
>>           List1.AddItem tmpItem, tmpIndex
>>           List1.ListIndex = List1.NewIndex
>>        End If
>>        List1.MousePointer = 0
>>        DragInProgress = False
>>        DragEnable = False
>>     End If

>> End Sub

>> LFS



Thu, 19 Apr 2001 03:00:00 GMT  
 How to drag and drop within same Listbox
You might want to check out the DragList control at the CCRP site. It has a
few other interesting features.

http://www.mvps.org/ccrp/controls/ccrpdraglist.htm

--

Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Quote:

>Will anyone share with me some code that allows dragging and dropping
>with in the same listbox so a user can reoder the list?

>TIA,

>Robin



Sat, 21 Apr 2001 03:00:00 GMT  
 How to drag and drop within same Listbox

I tried to apply this technique to a treeview but I am having problems.  The
only attribue I can find to tell where I am is "SelectedItem" but it is the
last item selected, not the one I just clicked on.  How do I know where I
just Clicked(I think this comes After the call to "MouseDown")

Thanks



Fri, 27 Apr 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Rearranging items within a Listbox with Drag/Drop?

2. Drag and Drop method of within a ListBox

3. Drag/drop within same control?

4. DBGrid and Drag and Drop within Grid

5. Drag and Drop within a user control

6. DBGrid and Drag and Drop within Grid

7. Drag and Drop within Treeview question

8. Drag & drop action within ListView and Treeview

9. Drag and Drop on Individual items within list boxes

10. Drag and Drop within treeview

11. Drag & Drop from within a Treeview

12. Drag&Drop within TreeView control.

 

 
Powered by phpBB® Forum Software