看看我移动listview记录的代码有什么问题?(10分)

  • 主题发起人 主题发起人 lcl_003
  • 开始时间 开始时间
L

lcl_003

Unregistered / Unconfirmed
GUEST, unregistred user!
我想控制listview的记录,让它上下移动。我写了个将记录向上移动的代码,可是只实现
了一部分,只有第一列的记录移动了,其他列没有重新付值。啊-----说起来太麻烦,看
看代码其实很简单

procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
j:Tstrings;
begin
s:=listview1.Items[listview1.ItemIndex-1].caption;
listview1.Items[listview1.ItemIndex-1].Caption:=listview1.Items[listview1.ItemIndex].Caption;
listview1.Items[listview1.ItemIndex].Caption:=s;

j:=listview1.Items[listview1.ItemIndex-1].SubItems;
listview1.Items[listview1.ItemIndex-1].SubItems:=listview1.Items[listview1.ItemIndex].SubItems;
listview1.Items[listview1.ItemIndex].SubItems:=j;

listview1.Selected:=listview1.Items[listview1.itemindex-1];
end;

哦,还有最后一行代码。我想控制listview的那行被选择,怎么不行?
 
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
j:Tstrings;
begin
s:=listview1.Items[listview1.ItemIndex-1].caption;
listview1.Items[listview1.ItemIndex-1].Caption:=listview1.Items[listview1.ItemIndex].Caption;
listview1.Items[listview1.ItemIndex].Caption:=s;
j := TstringList.Create;
j.Assign(Listview1.Items[listview1.ItemIndex-1].SubItems);
listview1.Items[listview1.ItemIndex-1].SubItems:=listview1.Items[listview1.ItemIndex].SubItems;
listview1.Items[listview1.ItemIndex].SubItems.Assign(j);
j.free;
listview1.SetFocus;
listview1.Selected:=listview1.Items[listview1.itemindex-1];
listview1.ItemFocused:=listview1.Items[listview1.itemindex-1];
end;
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部