views:

362

answers:

1

Hello,

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.

+7  A: 

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;
RRUZ
John, I think this is what you need. If it is not, you will need to explain better the question. Regards.
Francis Lee
I got a much better idea. ListView1.Items.item[X].subitems.Strings[Y] := 'String at subitem Y on item X'; :) +1 and accepted though.
John