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

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 10552
Including, how can I reposition the item in the listbox by drag/drop?

"VB Programmer" <do**@emailme.com> wrote in message
news:OK**************@TK2MSFTNGP15.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*****@optonline.net.

Bernie Yaeger

"VB Programmer" <do**@emailme.com> wrote in message
news:OK**************@TK2MSFTNGP15.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*****@optonline.net, tell me your email address,
and I will send it to you.

HTH,

Bernie Yaeger

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

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

Dim Index As Integer

' Determines which item was selected.

frombox3 = sender

Index = frombox3.IndexFromPoint(Pt)

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

If Index >= 0 Then

frombox3.DoDragDrop(frombox3.Items(Index), DragDropEffects.Move)

End If

End Sub

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

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

Dim Index As Integer

' Determines which item was selected.

tobox3 = sender

Index = tobox3.IndexFromPoint(Pt)

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

If Index >= 0 Then

tobox3.DoDragDrop(tobox3.Items(Index), DragDropEffects.Move)

End If

End Sub

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

frombox3.Items.Add(e.Data.GetData(DataFormats.Text ).ToString)

tobox3.Items.Remove(e.Data.GetData(DataFormats.Tex t).ToString)

End Sub

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

tobox3.Items.Add(e.Data.GetData(DataFormats.Text). ToString)

frombox3.Items.Remove(e.Data.GetData(DataFormats.T ext).ToString)

End Sub

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

Dim x As Integer

x =
tobox3.FindStringExact(e.Data.GetData(DataFormats. Text).ToString, -1)

If x <> -1 Then

Exit Sub

End If

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

e.Effect = DragDropEffects.Move

Else

e.Effect = DragDropEffects.None

End If

End Sub

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

Dim x As Integer

x =
frombox3.FindStringExact(e.Data.GetData(DataFormat s.Text).ToString, -1)

If x <> -1 Then

Exit Sub

End If

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

e.Effect = DragDropEffects.Move

Else

e.Effect = DragDropEffects.None

End If

End Sub

"VB Programmer" <do**@emailme.com> wrote in message
news:OK**************@TK2MSFTNGP15.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
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...
6
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...
2
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...
1
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...
4
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...
2
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...
7
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...
0
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...
5
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
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...

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.