Forum: VB.NET |
Thema:
Re: ListBox - Drag & Drop |
Von:
Timo Ulrich (
03.06.2005 10:45) |
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
Dim lb As ListBox = CType(sender, ListBox)
Dim pt As New Point(e.X, e.Y)
Dim index As Integer = lb.IndexFromPoint(pt)
If index >= 0 Then
lb.DoDragDrop(lb.Items(index).ToString(), DragDropEffects.Copy)
End If
End Sub
Private Sub Listbox2_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles ListBox2.DragDrop
If (e.Data.GetDataPresent(GetType(System.String))) Then
Dim item As Object = CType(e.Data.GetData(GetType(System.String)), System.Object)
If (e.Effect = DragDropEffects.Copy Or _
e.Effect = DragDropEffects.Move) Then
If (ListBox1.SelectedIndex.ToString() <> ListBox.NoMatches) Then
ListBox2.Items.Insert(ListBox1.SelectedIndex.ToString(), item)
Else
ListBox2.Items.Add(item)
End If
End If
End If
End Sub
Private Sub ListBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragEnter
If e.Data.GetDataPresent("Text") Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Vorher zwei Listboxen erstellen (Bezeichnung Listbox1 und Listbox2) und mit ein paar Elementen füllen.
He likes to topple those who have the farthest to fall.
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!