Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old September 7th, 2003, 07:18 PM
Osco Osco is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 Osco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Drag and Drop Controls?

I've been wanting to make a program that is like the Microsoft Visual Basic program itself, that lets the user move the controls around on the form, such as moving the buttons, and text boxes. How do I go about starting this? I've read everywhere and can't seem to find anything on it, there's only OLE and copying pictures into a program.

Reply With Quote
  #2  
Old September 9th, 2003, 01:41 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
This example shows you how to enable the user to drop and drag items between two list boxes. Add two listboxes to your form, and insert the following code.

Private Sub Form_Load()
' Populate the list
List1.AddItem "James"
List1.AddItem "Frederick"
List1.AddItem "Ann"
List1.AddItem "Paul"
List1.AddItem "Sarah"
List1.OLEDropMode = 1
List2.OLEDropMode = 1
End Sub

' Code managing dropping from list one
' to list two
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.OLEDrag ' Begin dragging
End Sub
Private Sub List1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
' Only allow moves
AllowedEffects = vbDropEffectMove
' Assign the ListBox selection to the DataObject
Data.SetData List1
End Sub
Private Sub List2_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim strList As String
' Check the format of the DataObject
If Not Data.GetFormat(vbCFText) Then Exit Sub
' Retrieve the text from the DataObject
strList = Data.GetData(vbCFText)
' If the item was not dropped on itself
If Not strList = List2.Text Then
List2.AddItem strList
'Remove the item from the ListBox
List1.RemoveItem List1.ListIndex
End If
End Sub
''
''
'' Code managing dropping from list one
'' to list two
''
Private Sub List2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
List2.OLEDrag ' Begin dragging
End Sub
Private Sub List2_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
' Only allow moves
AllowedEffects = vbDropEffectMove
' Assign the ListBox selection to the DataObject
Data.SetData List2
End Sub
Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim strList As String
' Check the format of the DataObject
If Not Data.GetFormat(vbCFText) Then Exit Sub
' Retrieve the text from the DataObject
strList = Data.GetData(vbCFText)
' If the item was not dropped on itself
If Not strList = List1.Text Then
List1.AddItem strList
'Remove the item from the ListBox
List2.RemoveItem List2.ListIndex
End If
End Sub


Hope it is helpful...

Reply With Quote
  #3  
Old September 29th, 2003, 04:15 PM
Blinky Blinky is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 2 Blinky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Blinky
Drag&Drop with Itemdata

Any chance you could amend this reply to include having the list entry's itemdata field transfer with the list entry?

This code rocks!
Thanks!
jody

Reply With Quote
  #4  
Old September 29th, 2003, 05:08 PM
Blinky Blinky is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 2 Blinky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Blinky
no reply needed

No reply needed. I figured it out.
I sorta cheated. Before the move event, i have a form-global variable record the itemdata of the list item being moved, and when it is assigned, i just assign the current global itemdata value to it's itemdata field with mystr(i think you called the contents that).

Also, this code rocks enough that you can make it three list boxes
All you have to do is instead of remove the item from one list, do it from both of the ones that aren't the recipient.
Since one is an error, put On Error Resume Next at the top, and you are ROLLIN!

A simple copy/past of list1 to list3 with renaming as needed does the rest.

thanks!
jody

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Drag and Drop Controls?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway