且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Delphi 7-如何使用标题从列表视图中删除项目

更新时间:2022-12-26 19:53:42

您可以使用类似的方法,该方法试图找到标题为 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;