Solved

Listbox drag and drop

Posted on 1998-11-17
4
358 Views
Last Modified: 2010-05-03
Hi, i'm fairly new to VB.
How would one drag an item in a listbox and drop it on another item in the same listbox, so that they would swop places?

Thanx for your help.
0
Comment
Question by:salocorgan
  • 2
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 40 total points
ID: 1445231
Here is a sample. Add a listbox to your form.
Copy this listbox and paste it again. Choose yes if he asks if your want to create a control array.

Option Explicit

Private Sub Form_Load()
    List1(0).OLEDragMode = 1
    List1(0).OLEDropMode = 1
    List1(1).OLEDragMode = 1
    List1(1).OLEDropMode = 1
    Dim i As Long
    For i = 1 To 10
        List1(i Mod 2).AddItem "item " & i
    Next
End Sub


Private Sub List1_OLEDragDrop(Index As Integer, Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    List1(Index).AddItem List1(1 - Index).List(Val(Data.GetData(vbCFText)))
    List1(1 - Index).RemoveItem Val(Data.GetData(vbCFText))
End Sub

Private Sub List1_OLEStartDrag(Index As Integer, Data As DataObject, AllowedEffects As Long)
    Data.SetData List1(Index).ListIndex, vbCFText
    AllowedEffects = 2
End Sub

0
 

Author Comment

by:salocorgan
ID: 1445232
Did i mention i'm using VB4?  OLEDrag_drop is unknown.....??
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1445233
Nope, you didn't mention that. So switch to VB5.
0
 

Author Comment

by:salocorgan
ID: 1445234
Thanx for your help, appreciate it.
Is there no way to do this is Vb4??
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Share codes 68 114
Vb.net Listview 9 76
VBA Shell can't Find Word document 11 39
VB6 - Convert HH:MM into Decimal 8 34
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now