Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Listbox drag and drop

Posted on 1998-11-17
4
376 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 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