Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a subitem in a listview?

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.

like image 420
Ivan Prodanov Avatar asked Jan 23 '23 07:01

Ivan Prodanov


1 Answers

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;
like image 133
RRUZ Avatar answered Jan 25 '23 21:01

RRUZ