473,703 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET 2005 - Drag & drop between listboxes

In VB.NET 2005 (winform) any sample code to drag & drop items between 2
listboxes? Thanks!
Nov 23 '05 #1
3 10594
Including, how can I reposition the item in the listbox by drag/drop?

"VB Programmer" <do**@emailme.c om> wrote in message
news:OK******** ******@TK2MSFTN GP15.phx.gbl...
In VB.NET 2005 (winform) any sample code to drag & drop items between 2
listboxes? Thanks!

Nov 23 '05 #2
Hi,

I see that no one has answered this yet. I have done some work in this area
but I don't have the time to respond right now. I will respond this
evening, however. Sorry for the delay.

If you don't hear from me by this evening, please email me at
be*****@optonli ne.net.

Bernie Yaeger

"VB Programmer" <do**@emailme.c om> wrote in message
news:OK******** ******@TK2MSFTN GP15.phx.gbl...
In VB.NET 2005 (winform) any sample code to drag & drop items between 2
listboxes? Thanks!

Nov 23 '05 #3
Hi,

I've done some work on listbox (listview) drag/drop, but I have to
acknowledge that I have no way of reordering the items as they pass into the
'drop' box. However, I do know a little about this, so here's my answer.

I note that you mention vb .net 2005 specifically: I am not aware of a
difference between it and vb .net 2003 regarding drag/drop, but I apologize
if there are differences and it would be worth looking into.

BTW - MS is almost empty on the subject of drag/drop - a modest intro here
and there, but that's about it (and some of those are incorrect).

In any event, you have to modify the mousedown, dragdrop, and dragenter
events. I have code samples below. However, I have found that I have more
control using listviews instead of listboxes. For the listview to work, you
have to set the listview's view to smallicon mode; the rest is similar but
slightly different (the itemdrag event has also to be altered). I have
actually created a dual listview drag/drop control. If you would like to
see it, just email me at be*****@optonli ne.net, tell me your email address,
and I will send it to you.

HTH,

Bernie Yaeger

Private Sub frombox3_MouseD own(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles frombox3.MouseD own

Dim Pt As New Point(e.X, e.Y)

Dim Index As Integer

' Determines which item was selected.

frombox3 = sender

Index = frombox3.IndexF romPoint(Pt)

' Starts a drag-and-drop operation with that item.

If Index >= 0 Then

frombox3.DoDrag Drop(frombox3.I tems(Index), DragDropEffects .Move)

End If

End Sub

Private Sub tobox3_MouseDow n(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles tobox3.MouseDow n

Dim Pt As New Point(e.X, e.Y)

Dim Index As Integer

' Determines which item was selected.

tobox3 = sender

Index = tobox3.IndexFro mPoint(Pt)

' Starts a drag-and-drop operation with that item.

If Index >= 0 Then

tobox3.DoDragDr op(tobox3.Items (Index), DragDropEffects .Move)

End If

End Sub

Private Sub frombox3_DragDr op(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles frombox3.DragDr op

frombox3.Items. Add(e.Data.GetD ata(DataFormats .Text).ToString )

tobox3.Items.Re move(e.Data.Get Data(DataFormat s.Text).ToStrin g)

End Sub

Private Sub tobox3_DragDrop (ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles tobox3.DragDrop

tobox3.Items.Ad d(e.Data.GetDat a(DataFormats.T ext).ToString)

frombox3.Items. Remove(e.Data.G etData(DataForm ats.Text).ToStr ing)

End Sub

Private Sub tobox3_DragEnte r(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles tobox3.DragEnte r

Dim x As Integer

x =
tobox3.FindStri ngExact(e.Data. GetData(DataFor mats.Text).ToSt ring, -1)

If x <> -1 Then

Exit Sub

End If

If (e.Data.GetData Present(DataFor mats.Text)) Then

e.Effect = DragDropEffects .Move

Else

e.Effect = DragDropEffects .None

End If

End Sub

Private Sub frombox3_DragEn ter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles frombox3.DragEn ter

Dim x As Integer

x =
frombox3.FindSt ringExact(e.Dat a.GetData(DataF ormats.Text).To String, -1)

If x <> -1 Then

Exit Sub

End If

If (e.Data.GetData Present(DataFor mats.Text)) Then

e.Effect = DragDropEffects .Move

Else

e.Effect = DragDropEffects .None

End If

End Sub

"VB Programmer" <do**@emailme.c om> wrote in message
news:OK******** ******@TK2MSFTN GP15.phx.gbl...
In VB.NET 2005 (winform) any sample code to drag & drop items between 2
listboxes? Thanks!

Nov 23 '05 #4

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

Similar topics

3
8166
by: James Radke | last post by:
Hello, I was curious, is it possible to create drag and drop interface from listbox to listbox on a webform application (i.e. vb.net)? Basically the application would need to load multiple listboxes with values from a database, allow the user to drag and drop from a listbox to a different listbox and would 'move' the item and update the database accordingly? If so, would anyone have any examples of how to do this?
6
4960
by: James Allen Bressem | last post by:
I was searching through the MSDN documentation trying to figure out how to do drag n drop and I found a sample program. The sample program did all sorts of fancy junk like dynamically create it's user controls etc. (pomp - is it really necessary to be so gaudy when trying to explain a simple point?) So, realizing the state of the economy and the period of history in which I was so unfortunately born, I spent the next 3 or so hours weeding...
2
1608
by: Dwayne Gaddy | last post by:
Hey all, I have a windows form with a list boxes. I have data binded the list boxes with data from my sql database. I want to use drag and drop to allow users to choose different options from the list boxes on the form and drag them into another empty list box that is not bound to any data when the form loads. I was wondering is it possible to use drag and drop with data binded list boxes ? If it is possible do you know of any place on...
1
2450
by: John Dalberg | last post by:
I have a couple of lisboxes in a form. I want to drag items from the first list and drop in the second list and sequence in the second list by dragging up and down. The same way in regular Windows apps. Is there a framework I can use to do this? John Dalberg
4
2556
by: Full NameEntry | last post by:
Hi all, I'm new to csharp... learning it by muddling my way though examples. In my current example, I'm trying to make a form with a bunch of listboxes that have drag and drop enabled amongst them... I found an example online in the form of a DragNDrop.cs file that I've included in my project (attached below).
2
1317
by: CNemo | last post by:
Hello friends! I need to do subj and VS03. No Atlas or something like this. Would be great if somebody may share a small sample how to do it. What i have in mind is like: 1. Create hidden field to hold source control name. 2. When mouse down, store name in this control. 3. Drag. 4. When drop, do postback from target control.
7
1778
by: Miro | last post by:
I think i have found my problem following an example ive searched for on the net. I am using vb.net 2005 express. What I am looking for is a drag drop from the toolbar that is an OleDbConnectionOleDbConnection and a OleDbDataAdapter so I can drag and drop these on the from, and Connect them to an mdb file. What I think I have come to, is that in 2005 Express you cannot do this.
0
1378
by: piercy | last post by:
i have two listboxes, lbData and lbTo. i need to drag and drop between the two. lbData.datasource = tblfilter; i need to be able to drag and drop the data from one to the other then on the other listbox display the same text but still have the same value behind. so when i submit the lbTo data should read something like Smith John 7A with a value of 657576 for each person in the lbTo.
5
13787
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with drag&drop on the same page (which was not possible). Now i´ve a new concept of the script, more object oriented. I´ve also commented the whole code so you guys can easier understand it engine. What exactly we need when trying to make a column drag &...
0
8761
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
8672
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9017
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
8969
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
7876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6594
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4434
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
3125
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
2462
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.