I have a list box that I want to be able to re-arrange with the mouse which I have working (needs improved though) and I would also like to be able to double-click on an item and change the text. The problem I am having is that when I try to double-click it tries to drag the item.
Here is the code for the Drag&Drop and for the Double-Click:
for the Drag&Drop I want to be able to draw a black line where the item will be placed, I'm not 100% sure on how to do that. Any ideas on how to have both of these work? I was thinking with the MouseDown have a timer trigger to wait for another click, but I was hoping there would be something simpler.
Here is the code for the Drag&Drop and for the Double-Click:
Code:
Private Sub lstFolderContents_DoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstFolderContents.DoubleClick
Dim index As Integer
Dim FileName As String
index = lstFolderContents.SelectedIndex
FileName = InputBox("Enter new file name", "Rename Item")
If Len(FileName) > 0 Then
lstFolderContents.Items.RemoveAt(index)
lstFolderContents.Items.Insert(index, FileName)
End If
End Sub
Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFolderContents.DragDrop
If e.Data.GetDataPresent(DataFormats.Text) Then
Dim dix As Integer = CInt(e.Data.GetData(DataFormats.Text))
Dim ix As Integer = lstFolderContents.IndexFromPoint(lstFolderContents.PointToClient(New Point(e.X, e.Y)))
lstFolderContents.IndexFromPoint(lstFolderContents.PointToClient(New Point(e.X, e.Y)))
If ix <> -1 Then
Dim obj As Object = lstFolderContents.Items(dix)
lstFolderContents.Items.Remove(obj)
lstFolderContents.Items.Insert(ix, obj)
End If
End If
End Sub
Private Sub ListBox1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFolderContents.DragOver
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Move
End If
End Sub
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstFolderContents.MouseDown
Dim ix As Integer = lstFolderContents.IndexFromPoint(e.Location)
If ix <> -1 Then
lstFolderContents.DoDragDrop(ix.ToString, DragDropEffects.Move)
End If
End Sub