您的当前位置:我要购书网>在线阅读>Delphi/Perl

listbox多选状态下的自拖与互拖

来源:互联网  作者:  发布:我要购物网收集整理  发布时间:2006-8-31 人气:213

unit Unit1;

file://yanlei:E_mail yanleiigis@21cn.com

interface

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

type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
aPoint: TPoint;
begin
aPoint.x := x;
aPoint.y := y;


if (source is Tlistbox) then
if ((source as Tlistbox).SelCount > 0) and
((sender as Tlistbox).ItemAtPos(apoint, true) <> -1)
and ((sender as Tlistbox).itematpos(apoint, true) <> (sender as Tlistbox).itemindex) then
begin
accept := true;
end;
end;

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
aPoint: TPoint;
st: string;
p: integer;
i, num: integer;
MYlBox: TStrings;
begin
aPoint.x := x;
aPoint.y := y;

p := (sender as Tlistbox).itematpos(aPoint, true);

MYlBox := Tstringlist.Create;
try
Num := (source as Tlistbox).Items.Count;
for i := num - 1 downto 0 do
begin
if (source as Tlistbox).Selected[i] then
begin
st := (source as Tlistbox).Items[i];
MYlBox.Add(st)

end;
end;
if p > -1 then
begin
for i := 0 to Mylbox.Count - 1 do
begin

(sender as Tlistbox).Items.Insert(p, mylbox[i])

end;
end
else
begin
for i := Mylbox.Count - 1 downto 0 do
begin
(sender as Tlistbox).Items.Add(mylbox[i])

end;

end;
(source as Tlistbox).DeleteSelected;
if P > -1 then
(sender as Tlistbox).Selected[p] := true;
finally
mylbox.Free;
end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
listbox2.OnDragDrop := listbox1.OnDragDrop;
listbox2.OnDragOver := listbox1.OnDragOver;
listbox1.MultiSelect := true;
listbox2.MultiSelect := true;
listbox1.DragMode := dmAutomatic;
listbox2.DragMode := dmAutomatic;end;end.

相关文章
· linux下tomcat的安装
· listview标题平面显示(vb)
· listview控件搜索函数(vb)
· listview 操作
· listbox多选状态下的自拖与互拖
· listview控件 -- 改良版,带箭头自动排序
· listcontrol的使用
· linux下配置jboss自动启动
· linux网络服务软件安装备忘录 ver 0.3
· listview custom draw - 不同行(列..
热点文章
%>
· creating user controls
· 提高fastreplace速度 (fstrrep.pas)
· asc ii 完整码表及简介
· 自动生成拼音(汉字反查到拼音)
· sql2000无法安装的解决办法
· 浏览器集成教学 自定义浏览器
· vc++技术内幕(第四版)笔记(第7章)
· mysql5.0中文乱码解决方案
· sql server日期计算
· vc下利用ado连接access数据库
 淘宝旺旺:我要购书网上书店『图书目录
本购书中心地址: 杭州市延安路111号清波商厦南楼D座(总部) 上海市闸北区老沪太路网上购书中心(沪部),  邮编:310002
电子邮件:books@51goushu.com  经营许可证编号:沪ICP备06038574号
版权所有 2003-2008 © All Rights Reserved .购书网