[RESOLVED] [2005] Reorder items within a listbox via drag and drop
Does anyone have an example of how to do this in VB.NET? There are plenty of examples out there for VB6, but I have not yet been able to find this for .NET.
Re: [2005] Reorder items within a listbox via drag and drop
Quote:
Originally Posted by BruceG
Does anyone have an example of how to do this in VB.NET? There are plenty of examples out there for VB6, but I have not yet been able to find this for .NET.
Hi,
Here's a link how to do it in C#, perhaps you can change it to VB.Net.
http://psiman.wordpress.com/2006/12/...reablelistbox/
Wkr,
sparrow1
Re: [2005] Reorder items within a listbox via drag and drop
Thanks, I appreciate the link, but that's a custom control and uses WPF. It is a little heavier than what I was looking for ...
Re: [2005] Reorder items within a listbox via drag and drop
Here is an example I put together real quick it should help you out.
Code:
Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
ListBox1.Items.Insert(ListBox1.IndexFromPoint(ListBox1.PointToClient(New Point(e.X, e.Y))), e.Data.GetData(DataFormats.Text))
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub
Private Sub ListBox1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragOver
e.Effect = DragDropEffects.Move
End Sub
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
ListBox1.DoDragDrop(ListBox1.Text, DragDropEffects.All)
End Sub
Re: [2005] Reorder items within a listbox via drag and drop
BEAUTIFUL!!! Thank you very much.