本文介绍了Delphi 7-如何使用标题从列表视图中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试根据标题删除列表视图项,但是我找不到解决方案,删除索引的唯一方法是使用索引:
i'm trying to delete a listview item based into caption, but I can not find a solution for this, the only way I can delete an item is using the index:
listview1.Items.Delete (0);
有人可以帮助我通过标题删除项目吗?
Can anyone help me to delete an item through the caption?
推荐答案
您可以使用类似的方法,该方法试图找到标题为 ListItem >项目2 ,并在找到它后将其删除:
You can use something like this, which attempts to locate a ListItem
with the caption Item 2
, and deletes it if it find it:
procedure TForm1.Button1Click(Sender: TObject);
var
LI: TListItem;
begin
LI := ListView1.FindCaption(0, 'Item 2', False, True, False);
if Assigned(LI) then
begin
ListView1.Selected := LI;
ListView1.DeleteSelected;
end;
end;
另一种不需要您首先选择项目的方法是删除找到的项目索引
:
An alternative which does not require you to select the item first would be to delete the found item by its Index
:
procedure TForm1.Button2Click(Sender: TObject);
var
LI: TListItem;
begin
LI := ListView1.FindCaption(0, 'Item 2', False, True, False);
if Assigned(LI) then
ListView1.Items.Delete(LI.Index);
end;
这篇关于Delphi 7-如何使用标题从列表视图中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!