Solved

DragDrop in Listbox

Posted on 1997-11-21
3
309 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…

696 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