Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.06.18;
Скачать: CL | DM;

Вниз

Перетаскивание в ListBox   Найти похожие ветки 

 
Blari   (2006-05-30 22:42) [0]

Подскажите пожалуйста как в ListBox перетаскивать элименты (менять местами) при помощи мыши. Или дайте ссылку на пример.


 
Gydvin ©   (2006-05-30 22:58) [1]

Быстренько накидал
Можно например так, только это надо доробатывать

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;

type
 TForm1 = class(TForm)
   ListBox1: TListBox;
   procedure ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
     Shift: TShiftState; X, Y: Integer);
   procedure FormCreate(Sender: TObject);
   procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
     Shift: TShiftState; X, Y: Integer);
 private
   { Private declarations }
   string1:integer;
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
 Shift: TShiftState; X, Y: Integer);
 var
 i:integer;
 s:string;
begin
if string1=-1 then exit;
i:=listbox1.ItemIndex;
if i=-1 then exit;
s:=listbox1.Items.Strings[string1];
listbox1.Items.Insert(i,s);
if i<string1 then inc(string1);
listbox1.Items.Delete(string1);
listbox1.ItemIndex:=i;
string1:=-1;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
string1:=-1;
end;

procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
 Shift: TShiftState; X, Y: Integer);
var
 i:integer;
begin
string1:=-1;
i:=listbox1.ItemIndex;
if i=-1 then exit;
string1:=i;

end;

end.


 
MBo ©   (2006-05-31 07:07) [2]

http://www.delphimaster.ru/articles/dragndrop/index.html


 
antonn ©   (2006-05-31 07:07) [3]

var IsMouseDown:boolean;
    nusel:integer;

procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
IsMouseDown:=true;
nusel:= Listbox1.ItemIndex;
end;

procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  IsMouseDown:=false;
end;

procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
var old:integer;
begin
if IsMouseDown then begin
    old:= listbox1.ItemIndex;
    if nusel >=ListBox1.Items.Count-1 then nusel:=ListBox1.Items.Count-1 else
         if nusel <=0 then  nusel:=0 ;
    if old >=ListBox1.Items.Count-1 then old:=ListBox1.Items.Count-1 else
         if old <=0 then  old:=0;
     ListBox1.Items.Move(nusel,old);
     nusel:= old ;
 end;
end;




Страницы: 1 вся ветка

Текущий архив: 2006.06.18;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.047 c
11-1127963931
dvk
2005-09-29 07:18
2006.06.18
KOL+MCK 2.13/ Проблемы с установкой


4-1142876934
Igor_thief
2006-03-20 20:48
2006.06.18
Insertion Marks and ListView


2-1149124445
qTorus
2006-06-01 05:14
2006.06.18
Объекты


11-1127844554
_Beginner_
2005-09-27 22:09
2006.06.18
Как перетягивать форму без заголовка?


15-1148374070
DillerXX
2006-05-23 12:47
2006.06.18
Помогите с визуальным обновлением :(