//增加 procedure TForm1.Button1Click(Sender: TObject); var lsItem: TListItem; begin lsItem := ListView1.Items.Add; lsItem.Caption := VarToStr(ListView1.Items.Count); lsItem.SubItems.Add(edit1.Text); lsItem.SubItems.Add(edit2.Text); edit1.Text := ''; Edit2.Text := ''; end;
//修改 procedure TForm1.Button2Click(Sender: TObject); begin ListView1.Selected.SubItems.Strings[0] := Edit1.Text; ListView1.Selected.SubItems.Strings[1] := edit2.Text; end;
//删除 procedure TForm1.Button3Click(Sender: TObject); begin ListView1.DeleteSelected; edit1.Text := ''; Edit2.Text := ''; end;//点击项目取值 procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); begin edit1.Text := Item.SubItems.Strings[0]; Edit2.Text := Item.SubItems.Strings[1]; end;
//循环判断Checkbox是否选中 procedure TForm1.Button4Click(Sender: TObject); var i: Integer; begin memo1.Clear; for i := 0 to ListView1.Items.Count - 1 do begin if ListView1.Items.Item[i].Checked then
begin memo1.Lines.Add(ListView1.Items.Item[i].Caption); memo1.Lines.Add(ListView1.Items.Item[i].SubItems.Strings[0]); memo1.Lines.Add(ListView1.Items.Item[i].SubItems.Strings[1]); end;
end; end;