Delphi:Listview中的Shift-Up和Shift-Down
发布时间:2020-12-15 09:19:20 所属栏目:大数据 来源:网络整理
导读:Listview控件中是否有一项功能可以上下移动项目? 解决方法 我没有很好地使用TListView(我主要使用数据库网格),我把你的问题作为学习的机会.以下代码是结果,大卫的答案更具视觉导向性.它有一些限制:它只会移动第一个选定的项目,当它移动项目时,vsicon和vsSm
|
Listview控件中是否有一项功能可以上下移动项目?
解决方法
我没有很好地使用TListView(我主要使用数据库网格),我把你的问题作为学习的机会.以下代码是结果,大卫的答案更具视觉导向性.它有一些限制:它只会移动第一个选定的项目,当它移动项目时,vsicon和vsSmallIcon的显示在移动后很奇怪.
procedure TForm1.btnDownClick(Sender: TObject);
var
Index: integer;
temp : TListItem;
begin
// use a button that cannot get focus,such as TSpeedButton
if ListView1.Focused then
if ListView1.SelCount>0 then
begin
Index := ListView1.Selected.Index;
if Index<ListView1.Items.Count then
begin
temp := ListView1.Items.Insert(Index+2);
temp.Assign(ListView1.Items.Item[Index]);
ListView1.Items.Delete(Index);
// fix display so moved item is selected/focused
ListView1.Selected := temp;
ListView1.ItemFocused := temp;
end;
end;
end;
procedure TForm1.btnUpClick(Sender: TObject);
var
Index: integer;
temp : TListItem;
begin
// use a button that cannot get focus,such as TSpeedButton
if ListView1.Focused then
if ListView1.SelCount>0 then
begin
Index := ListView1.Selected.Index;
if Index>0 then
begin
temp := ListView1.Items.Insert(Index-1);
temp.Assign(ListView1.Items.Item[Index+1]);
ListView1.Items.Delete(Index+1);
// fix display so moved item is selected/focused
ListView1.Selected := temp;
ListView1.ItemFocused := temp;
end;
end;
end;
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
