Главная страница
    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.45 MB
Время: 0.01 c
2-1148988561
wsih
2006-05-30 15:29
2006.06.18
Как пробежаться по всем веткам узла


15-1148230125
RUNaum
2006-05-21 20:48
2006.06.18
psql и че-то не допирает...


4-1142905761
powerchute
2006-03-21 04:49
2006.06.18
Управление настройками электропитания


1-1147412552
Chaser
2006-05-12 09:42
2006.06.18
Отображение иконок в TreeView


1-1147283808
Андрей2500
2006-05-10 21:56
2006.06.18
сортировка Stringgrid по алфавиту





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский