向上: procedure TForm1.Button1Click(Sender: TObject); var tempobject:Tobject; tempitem:Tlistitem; selectitem:Tlistitem; index:integer; begin selectitem:=listview1.Selected; tempitem:=selectitem; index:=tempitem.Index; if index>0 then listview1.Items.Insert(index-1).Assign(tempitem); selectitem.Free; tempitem.Selected:=true; end;往下类似
哦,你说的这个意思啊,我还以为你是要滚动呢! 如: RobinHZ(熊掌) 所说,插入、删除
向下: procedure TForm1.Button2Click(Sender: TObject); var tempobject:Tobject; tempitem:Tlistitem; selectitem:Tlistitem; index:integer; begin selectitem:=listview1.Selected; tempitem:=selectitem; index:=tempitem.Index; if index<>listview1.items.count-1 then listview1.Items.Insert(index+1).Assign(tempitem); selectitem.Free; tempitem.Selected:=true; end;
tempitem.selected:=true 去掉,写错了
var selectno,tono:Integer; fieldstr:String; begin selectno:= ListView1.Selected.Index; if selectno<0 then begin Application.MessageBox('XXX提示警告!','提示信息',0+mb_iconwarning); Listview1.SetFocus; Exit; end else begin fieldstr:=Listview1.Items[selectno].Caption; tono:=selectno-1; if tono<0 then tono:=Listview1.Items.Count-1; Listview1.Items[selectno]:=Listview1.Items[tono]; Listview1.Items[tono].Caption:=fieldstr; Listview1.Items[tono].Selected:=True; end; end;
直接操作 INDEX了 基本就可以了
var selectno,tono:Integer; fieldstr:String; begin selectno:= ListView1.Selected.Index; if selectno<0 then begin Application.MessageBox('XXX提示警告!','提示信息',0+mb_iconwarning); Listview1.SetFocus; Exit; end else begin fieldstr:=Listview1.Items[selectno].Caption; tono:=selectno-1; if tono<0 then tono:=Listview1.Items.Count-1; Listview1.Items[selectno]:=Listview1.Items[tono]; Listview1.Items[tono].Caption:=fieldstr; Listview1.Items[tono].Selected:=True; end; ListView1.SetFocus; end;
真是不好意思,向下移动的没有调试就给你了procedure TForm1.Button2Click(Sender: TObject); var tempobject:Tobject; tempitem:Tlistitem; selectitem:Tlistitem; index:integer; begin selectitem:=listview1.Selected; tempitem:=selectitem; index:=tempitem.Index; if index<>listview1.Items.Count-1 then begin listview1.Items.Insert(index+2).Assign(tempitem); selectitem.Free; end; end;
procedure TForm1.Button1Click(Sender: TObject);
var
tempobject:Tobject;
tempitem:Tlistitem;
selectitem:Tlistitem;
index:integer;
begin
selectitem:=listview1.Selected;
tempitem:=selectitem;
index:=tempitem.Index;
if index>0 then
listview1.Items.Insert(index-1).Assign(tempitem);
selectitem.Free;
tempitem.Selected:=true;
end;往下类似
如: RobinHZ(熊掌) 所说,插入、删除
procedure TForm1.Button2Click(Sender: TObject);
var
tempobject:Tobject;
tempitem:Tlistitem;
selectitem:Tlistitem;
index:integer;
begin
selectitem:=listview1.Selected;
tempitem:=selectitem;
index:=tempitem.Index;
if index<>listview1.items.count-1 then
listview1.Items.Insert(index+1).Assign(tempitem);
selectitem.Free;
tempitem.Selected:=true;
end;
去掉,写错了
selectno,tono:Integer;
fieldstr:String;
begin
selectno:= ListView1.Selected.Index;
if selectno<0 then begin
Application.MessageBox('XXX提示警告!','提示信息',0+mb_iconwarning);
Listview1.SetFocus;
Exit;
end
else begin
fieldstr:=Listview1.Items[selectno].Caption;
tono:=selectno-1;
if tono<0 then tono:=Listview1.Items.Count-1;
Listview1.Items[selectno]:=Listview1.Items[tono];
Listview1.Items[tono].Caption:=fieldstr;
Listview1.Items[tono].Selected:=True;
end;
end;
基本就可以了
selectno,tono:Integer;
fieldstr:String;
begin
selectno:= ListView1.Selected.Index;
if selectno<0 then begin
Application.MessageBox('XXX提示警告!','提示信息',0+mb_iconwarning);
Listview1.SetFocus;
Exit;
end
else begin
fieldstr:=Listview1.Items[selectno].Caption;
tono:=selectno-1;
if tono<0 then tono:=Listview1.Items.Count-1;
Listview1.Items[selectno]:=Listview1.Items[tono];
Listview1.Items[tono].Caption:=fieldstr;
Listview1.Items[tono].Selected:=True;
end;
ListView1.SetFocus;
end;
我只要不选最后一个就没反应。
选最后一个就删除最后一个。这有什么用啊
var
tempobject:Tobject;
tempitem:Tlistitem;
selectitem:Tlistitem;
index:integer;
begin
selectitem:=listview1.Selected;
tempitem:=selectitem;
index:=tempitem.Index;
if index<>listview1.Items.Count-1 then
begin
listview1.Items.Insert(index+2).Assign(tempitem);
selectitem.Free;
end;
end;