Solved

DragDrop in Listbox

Posted on 1997-11-21
3
306 Views
Last Modified: 2010-04-04
Can somebody give me an example of how I should a dragdrop action in a TListBox? (The user can select an item and drag it to another item to change the sequence of the items)
(I've done it alteady,but I'm afraid my coding is a bit sloppy )
Thanks again!
PS I'm now working on my first Delphi Project,and I love it! But there's a lot of 'simple' things I just can't figure out  from the books or Delphi Help,so I very glad with all your help.
0
Comment
Question by:lizzzard
3 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1351398
Hi lizzzard,

Dragging and dropping in the same listbox or from one to another listbox?


0
 

Author Comment

by:lizzzard
ID: 1351399
Hi ZifNab,
In the same listbox.
0
 
LVL 1

Accepted Solution

by:
TheSwine earned 50 total points
ID: 1351400
Here is a working source:

procedure TEnColumnsEditor.ColsListMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  MoveFrom := ColsList.ItemAtPos(Point(X,Y),True);
  if MoveFrom <> -1 then ColsList.BeginDrag(False);
end;

procedure TEnColumnsEditor.ColsListDragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  Accept := (ColsList.ItemAtPos(Point(X,Y),True) <> - 1) and
    (ColsList.ItemAtPos(Point(X,Y),True) <> MoveFrom);
end;

procedure TEnColumnsEditor.ColsListDragDrop(Sender, Source: TObject; X,
  Y: Integer);
begin
  ColsList.EndDrag(True);
    NewColumns.Exchange(MoveFrom, ColsList.ItemAtPos(Point(X,Y),True));
  RefreshList;
end;

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

18 Experts available now in Live!

Get 1:1 Help Now