472,805 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 10470
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...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.