Вниз
Скачать: 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 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.024 c
2-1148850258
wsih
2006-05-29 01:04
2006.06.18
Сортировка TreeView


2-1149249027
XTD
2006-06-02 15:50
2006.06.18
Unsatisfied forward or external declaration: ????


2-1149001787
Махоня
2006-05-30 19:09
2006.06.18
как связать Word c Delphi


15-1148723193
Kolan
2006-05-27 13:46
2006.06.18
Как преобразовать 4 байта в тип Float


15-1148383182
musulman
2006-05-23 15:19
2006.06.18
php help me plz




   Наверх