473,668 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Dra gDrop(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstSelected.Dra gDrop
lstSelected.Ite ms.Add(e.Data.G etData(DataForm ats.Text).ToStr ing)
lstAvailable.It ems.Remove(e.Da ta.GetData(Data Formats.Text).T oString)
End Sub

Private Sub lstAvailable_Dr agDrop(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstAvailable.Dr agDrop
lstAvailable.It ems.Add(e.Data. GetData(DataFor mats.Text).ToSt ring)
lstSelected.Ite ms.Remove(e.Dat a.GetData(DataF ormats.Text).To String)
End Sub

Private Sub lstSelected_Dra gEnter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstSelected.Dra gEnter

If (e.Data.GetData Present(DataFor mats.Text)) Then
e.Effect = DragDropEffects .Move
Else
e.Effect = DragDropEffects .None
End If

End Sub

Private Sub lstAvailable_Dr agEnter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstAvailable.Dr agEnter

If (e.Data.GetData Present(DataFor mats.Text)) Then
e.Effect = DragDropEffects .Move
Else
e.Effect = DragDropEffects .None
End If

End Sub

Private Sub lstAvailable_Mo useDown(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles lstAvailable.Mo useDown

strDragDrop = lstAvailable.Te xt
lstAvailable.Do DragDrop(strDra gDrop, DragDropEffects .Move)
End Sub

Private Sub lstSelected_Mou seDown(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles lstSelected.Mou seDown

strDragDrop = lstSelected.Tex t
lstSelected.DoD ragDrop(strDrag Drop, DragDropEffects .Move)
End Sub
Private Sub lstAvailable_Mo useDoubleClick( ByVal sender As Object, ByVal e As
System.EventArg s) Handles lstAvailable.Do ubleClick
lstSelected.Ite ms.Add(lstAvail able.SelectedIt em)
lstAvailable.It ems.Remove(lstA vailable.Select edItem)
End Sub

Private Sub lstSelected_Dou bleClick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles lstSelected.Dou bleClick
lstAvailable.It ems.Add(lstSele cted.SelectedIt em)
lstSelected.Ite ms.Remove(lstSe lected.Selected Item)
End Sub

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
1 1724
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
6436
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 ListView.Items.Add(), . I see that it is a virtual method so it should be easy to do. If anyone can help I would appreciate it greatly. I can do what I need to do in a different way this would just make everything significantly cleaner and eaasier...
6
3401
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 listview, removing the item obviously keeps everything fine but the second I use insert the item is added to the *end* of the listview. Does anyone have any tips on how I can solve this issue?? Call Items.Remove(SourceItem)
12
7474
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 the overall size of the listview. My question therefore is, how can I tell if the items I have added will fit in the listview at its given height? A secondary one, just for interest sake...is there a way to determine the exact heght needed...
3
3297
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 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...
5
10076
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 because the ListView seems to be trying to "re-select" items that are no longer there! for example, giventhat I have 3 items in my list: Select the first and remove it - no problem.
1
2054
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 New ListView listView1.Bounds = New Rectangle(New Point(10, 10), New Size(300, 200)) ' Set the view to show details.
0
1886
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 form every thing works fine: checking items by code as well as checking with mouse: Using the CheckdItems Property is confused too.
2
6825
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 form every thing works fine: checking items by code
1
8347
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 FillListViewFromFile(string path) {
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8570
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2781
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.