首页 > 代码库 > TListView列表拒绝添加重复信息

TListView列表拒绝添加重复信息

 
//TListView列表拒绝添加重复信息
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  if (Trim(Edit1.Text)<>‘‘) then
  begin
    for i := 0 to ListView1.Items.Count-1 do
    if Trim(Edit1.Text) = Trim(ListView1.Items[i].Caption) then
    begin
      Exit;
    end;
  end;
  ListView1.Items.Add.Caption:=Edit1.Text;
end;
 
 
 


function ItemExist(Text:string;ListView:TListView):Boolean;
var
  i: Integer;
begin
  Result:=False;
  if (Trim(Text)<>‘‘) then
  begin
    for i := 0 to ListView.Items.Count-1 do
    if Trim(Text) = Trim(ListView.Items[i].Caption) then
    begin
      Result:=True;
      Exit;
    end;
  end;
  Result:=False;
end;


 
procedure TForm1.Button6Click(Sender: TObject);
begin
  if not ItemExist(Edit1.Text,ListView1) then
      ListView1.Items.Add.Caption:=Edit1.Text;
end;


来自为知笔记(Wiz)


附件列表