procedure TForm1.butAddClick(Sender: TObject);
var
RowItem:TListItem;
begin
Rowitem := ListView1.Items.Add;
Rowitem.Caption := edit1col.Text; // first column
Rowitem.SubItems.Add(edit2col.Text); // second column
Rowitem.SubItems.Add(edit3col.Text); // third column
end;
procedure TForm1.butReadClick(Sender: TObject);
var
Item:TListItem;
begin
Item:= ListView1.Items.Item[StrtoInt(editItem.Text)];
edit1col.Text := Item.Caption;
edit2col.Text := Item.SubItems[0];
edit3col.Text:= Item.SubItems[1];
end;
procedure TForm1.butClearClick(Sender: TObject);
begin
ListView1.Items.Clear;
end;
procedure TForm1.butModifyClick(Sender: TObject);
var
Item:TListItem;
begin
Item:= ListView1.Items.Item[StrtoInt(editItem.Text)];
Item.Caption:= edit1col.Text;
Item.SubItems[0] := edit2col.Text;
Item.SubItems[1] := edit3col.Text;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//ListView1.Items.Clear;
end;
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
var
listviewcurrentindex: integer;
begin
if Selected then begin // without selected check, click on blank row will cause error
listviewcurrentindex := Listview1.Selected.Index;
editItem.Text := InttoStr(listviewcurrentindex);
edit1col.Text := Listview1.Selected.Caption;
edit2col.Text := Listview1.Selected.SubItems.Strings[0];
edit3col.Text:= Listview1.Selected.SubItems.Strings[1];
end;
end;