We help IT Professionals succeed at work.

Drag and Drop in a List Box

HarisIV
HarisIV asked
on
Medium Priority
195 Views
Last Modified: 2010-04-06
I am looking for an example how to drag items within a list box
Comment
Watch Question

Commented:
Are you working in delphi 2 or 1?

Can you give more details of what you want to do?

Cheers
Richard

Author

Commented:
I am working in Delphi 2 and I want to be able to drag an item for a position in the list and move it in another position in thelist.
Commented:
Haris

Here goes, not the most elegant, but it works.

in the OnMouseDown event for the listbox add the following:

lastpos := listbox1.itemindex;

in the OnMouseUp event add:

listbox1.items.move(lastpos,listbox1.itemindex)

Also, add a global variable for the form:

var form1 : TForm;
    lastpos : integer;

This should do it, you can also change the cursor while dragging if you want to (I'll send info if you want to)

Cheers
Richard

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.