How to change a subitem in a listview?

10,191

try this

//Add a item

var
  ListItem : TListItem;
begin

  ListViewItem.Items.BeginUpdate;
try
    ListItem := ListViewItem.Items.Add;
    ListItem.Caption := 'First Column Value';
    ListItem.SubItems.Add('Second Column Value');
    ListItem.SubItems.Add('Third Column Value');
finally  
ListViewItem.Items.EndUpdate;
end;

end;

//Edit a Item

var
  ListItem : TListItem;
begin

  ListViewItem.Items.BeginUpdate;
try
    ListItem := Listview.items.item[X];
    ListItem.Caption := 'New first Column Value';
    ListItem.SubItems[0]:='New Second Column Value';
    ListItem.SubItems[1]:='New Third Column Value';
finally  
ListViewItem.Items.EndUpdate;
end;

end;
Share:
10,191
P. Duw
Author by

P. Duw

Updated on June 04, 2022

Comments

  • P. Duw
    P. Duw almost 2 years

    I used Listview.items.item[X].caption for changing the first column in a listbox,but now I have to change further at runtime.The only way I see is getting the item from listbox as TListItem ,editing it,add it and change position,but that doesn't suit it,because I have many items on the listview.

    Is there a simpler way to accomplish this ,like the way I change the first item?

    Thanks in advance.

  • Francis Lee
    Francis Lee over 14 years
    John, I think this is what you need. If it is not, you will need to explain better the question. Regards.