473,288 Members | 1,729 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,288 software developers and data experts.

DragnDrop Listview Items

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 items. I tried setting up
an array to capture the selected items and then move them with the dragndrop
code, but after selecting the items when the user clicks on the items to
drag them the selection goes back to one item. Also I have code for the
listbox doubleclick event that moves whatever item is doubleclicked in one
listbox to the other. This worked fine until I added the dragndrop code to
the mousedown event, now instead of a doubleclick event I get two mousedown
events. I am sure someone has done this and I would appreciate seeing the
code.

Thanks

Thomas

Private Sub lstSelected_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles lstSelected.DragDrop
lstSelected.Items.Add(e.Data.GetData(DataFormats.T ext).ToString)
lstAvailable.Items.Remove(e.Data.GetData(DataForma ts.Text).ToString)
End Sub

Private Sub lstAvailable_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles lstAvailable.DragDrop
lstAvailable.Items.Add(e.Data.GetData(DataFormats. Text).ToString)
lstSelected.Items.Remove(e.Data.GetData(DataFormat s.Text).ToString)
End Sub

Private Sub lstSelected_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles lstSelected.DragEnter

If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If

End Sub

Private Sub lstAvailable_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles lstAvailable.DragEnter

If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If

End Sub

Private Sub lstAvailable_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstAvailable.MouseDown

strDragDrop = lstAvailable.Text
lstAvailable.DoDragDrop(strDragDrop, DragDropEffects.Move)
End Sub

Private Sub lstSelected_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstSelected.MouseDown

strDragDrop = lstSelected.Text
lstSelected.DoDragDrop(strDragDrop, DragDropEffects.Move)
End Sub
Private Sub lstAvailable_MouseDoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lstAvailable.DoubleClick
lstSelected.Items.Add(lstAvailable.SelectedItem)
lstAvailable.Items.Remove(lstAvailable.SelectedIte m)
End Sub

Private Sub lstSelected_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lstSelected.DoubleClick
lstAvailable.Items.Add(lstSelected.SelectedItem)
lstSelected.Items.Remove(lstSelected.SelectedItem)
End Sub

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
1 1696
Have a look at this article. It should give you a general idea:

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

There is also an article that says there are problems at run time with the
listview control:

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

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #2

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

Similar topics

7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
6
by: Nick | last post by:
Hi there, I'm trying to implement drag-drop for my listview control in large icon view mode. Unfortunately the order of the items gets completely messed up upon inserting the item back into the...
12
by: J L | last post by:
When I fill a listview, I resize the columns to fit the data. I need to know if the data will fit vertically or if there will be a vertical scroll bar. I need to know this so I can allow for it on...
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...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
1
by: samoore33 | last post by:
I found this code on MSDN, and it works great. It creates a ListView dynamically and add items to it and all. It is great. I have changed a few of the column names to suit me. Dim listView1 As...
0
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, In my application I need to periodically remove all current items from a ListView and add a new set into it. The following abbreviated code contains the basic idea: private void...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.