Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2006.06.18;
Скачать: [xml.tar.bz2];

Вниз

Перетаскивание в 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;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.45 MB
Время: 0.16 c
15-1148636830
korotkova
2006-05-26 13:47
2006.06.18
Открыта вакансия!


6-1139373281
DelphiN!
2006-02-08 07:34
2006.06.18
Отключить все горячие клавишиш в TWebBrowser


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


3-1145170476
Виталька 2006
2006-04-16 10:54
2006.06.18
Конфигурация BDE при установке


3-1145530582
ttt_111
2006-04-20 14:56
2006.06.18
Как отработать событие?





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский