all groups > vb.net controls > june 2007 >
You're in the

vb.net controls

group:

List box rearrange items


List box rearrange items Lou
6/2/2007 11:26:40 PM
vb.net controls:
How do you implement drag and drop within the same listbox control to
re-arrainge the order of the items?
-Lou

Re: List box rearrange items Petar Atanasov
6/4/2007 12:00:00 AM
[quoted text, click to view]

Hi Lou,

Check out the discussion here:
http://www.developerfusion.co.uk/forums/thread/111320/#111320

HTH,
Petar Atanasov
Re: List box rearrange items Lou
6/4/2007 10:58:29 AM
Any VB code examples?

[quoted text, click to view]

Re: List box rearrange items Lou
6/4/2007 11:14:34 AM
That code is for dragging between 2 list boxes, i need to drag within 1
listbox?

[quoted text, click to view]

Re: List box rearrange items Lou
6/4/2007 11:38:02 AM
That code, as the thread reads , doesn't work within the same listbox.
I'll keep looking.
Thanks.
if anyone has a link to how this is done please post it.
Thanks
-Lou

[quoted text, click to view]

Re: List box rearrange items Lou
6/4/2007 12:07:21 PM
Ureka, I found it. Here is the code...

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

With ListBox1

..Items.Add("AAA")

..Items.Add("BBB")

..Items.Add("CCC")

..Items.Add("DDD")

End With

End Sub

Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop

If e.Data.GetDataPresent(DataFormats.Text) Then

Dim dix As Integer = CInt(e.Data.GetData(DataFormats.Text))

Dim ix As Integer = ListBox1.IndexFromPoint(ListBox1.PointToClient(New
Point(e.X, e.Y)))

If ix <> -1 Then

Dim obj As Object = ListBox1.Items(dix)

ListBox1.Items.Remove(obj)

ListBox1.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 ListBox1.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 ListBox1.MouseDown

Dim ix As Integer = ListBox1.IndexFromPoint(e.Location)

If ix <> -1 Then

ListBox1.DoDragDrop(ix.ToString, DragDropEffects.Move)

End If

End Sub

End Class


[quoted text, click to view]

Re: List box rearrange items PlatinumBay
6/4/2007 11:32:58 PM
Lou,

Check out this thread: http://www.vbdotnetforums.com/showthread.php?t=11575

There are some links and sample code further down.

Hope this helps,


Steve

[quoted text, click to view]

Re: List box rearrange items Lou
6/5/2007 11:59:48 PM
Yes, that example is excellent!
Thanks.

[quoted text, click to view]

AddThis Social Bookmark Button