473,320 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Reordering listbox items with drag and drop

Can anyone point me to a tutorial on reordering items within a single
listbox using the mouse, ie drag and drop, specifically with vb.net.
Google shows me various half-references eg to related controls, vb6 or
whatever, but nothing that seems to relate specifically to vb.bet and
reordering within a single listbox control.

Thanks
JGD
Nov 21 '05 #1
5 6842
Hi John,

Here's the solution:

http://support.microsoft.com/default...b;en-us;306969

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #2
Thanks but that's only a partial solution in that it doesn't (unless
I've missed something) cover the particular circumstance that I'm
stuck on, ie drap and drop _within_ a single listbox in order to
reorder items that are already listed. (And how best to manage the
reordering of items once a DragDrop event has been generated.)

What I most need to know is whether there's a relatively simple
solution to this or alternatively, if not, then I should maybe cut my
losses and try a different approach to the problem, eg by using
up/down cursor keys. But it would be neatest to use drag/drop.

JGD
On Fri, 17 Jun 2005 22:57:05 +0100, "Crouchie1998"
<cr**********@spamcop.net> wrote:
Hi John,

Here's the solution:

http://support.microsoft.com/default...b;en-us;306969

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE


Nov 21 '05 #3
I pulled this code from one of my personal projects. This should do
what you want. It looks like the second subroutine does nothing, but I
may have needed it for some reason, or it may have been for an idea
that I was working on that I never got back to.

At any rate, watch the word wrapping.
Private Sub lvw_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles lvw.DragDrop
Try
Dim i As Integer
Dim l_Point As Point = lvw.PointToClient(New Point(e.X,
e.Y))
Dim l_Item As ListViewItem = lvw.GetItemAt(l_Point.X,
l_Point.Y)
Dim l_Items() As ListViewItem =
e.Data.GetData("System.Windows.Forms.ListViewItem( )")
Dim l_DropIndex As Integer = l_Item.Index

btnDelete_Click(sender, New System.EventArgs)
For Each l_Item In l_Items
lvw.Items.Insert(l_DropIndex + i, l_Items(i))
i = i + 1
Next
Catch ex As Exception
End Try
End Sub

Private Sub lvw_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles lvw.DragEnter
If e.Data.GetDataPresent("System.Windows.Forms.ListVi ewItem()")
Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub

Private Sub lvw_ItemDrag(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemDragEventArgs) Handles lvw.ItemDrag
Dim myItem As ListViewItem
Dim myItems(sender.SelectedItems.Count - 1) As ListViewItem
Dim i As Integer = 0

' Loop though the SelectedItems collection for the source.
For Each myItem In sender.SelectedItems
' Add the ListViewItem to the array of ListViewItems.
myItems(i) = myItem
i = i + 1
Next
' Create a DataObject containg the array of ListViewItems.
sender.DoDragDrop(New
DataObject("System.Windows.Forms.ListViewItem()", myItems),
DragDropEffects.Move)
End Sub

Nov 21 '05 #4
Sorry, I didn't notice at first that you stated a listbox instead of a
listview. I don't use listboxes, so I don't know if that my above code
will work for you.

Nov 21 '05 #5
Sorry, I didn't notice at first that you stated a listbox instead of a
listview. I don't use listboxes, so I don't know if that my above code
will work for you.

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Guarnieri | last post by:
Hi All, I need some code to drag items in a list box either up or down along with not just the text but with the itemdata too. Can anyone hook me up? TIA John
0
by: Eric | last post by:
I'm trying to implement Drag and Drop with objects in list boxes and I'm not having any success. I can drag and drop strings, but when I try to change the code to drag an object it allows me to pick...
5
by: CoolWriter | last post by:
Hi, How can I drag and drop the items of a ListBox? For example, how can I drag the first item to the third items position in a ListBox? Thanks.
0
by: L.Peter | last post by:
Dear Group, I am doing Drag and Drop function and see this problem if I select 3 from listBox1 and drag to listBox2, the value in listBox1 is not updated, even I move (or use up and down keyboard)...
3
by: Dean Slindee | last post by:
In a checked listbox, I am allowing drag/drop of the items within (resequencing). Problem is, when dropping a checked item, the checked state always reverts to unchecked (unwanted). Anyone know...
1
by: Zyrthofar Blackcloak | last post by:
Hi everyone I have a listbox with more items in it than is printed on screen. I need the index number of the first shown item to move another listbox to the same position... Explained differently,...
4
by: Bernie Yaeger | last post by:
I've been able to get a pair of listboxes to pass data from one to the other successfully, but only one selected item at a time. If I change the listbox mode of both the multiextended, it only...
11
by: John Dann | last post by:
I'm still struggling to find a way of reordering the items within the same single listbox with drag and drop. I think I've got the drag working but it's the drop code I can't figure out. What I...
3
by: thomasp | last post by:
Has anyone got some sample code to do drag and drop from one listbox to another listbox using VB.Net 2005. The below code works for draging and droping one at a time, but not for multiselected...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.