views:

209

answers:

2

hi all

I want to update values in a TListView. I tryed this

...
lvProcess : TListView;
liEdit : TlistItem;
...
   liEdit:=lvProcess.Items.Item[1];
   liEdit.Caption:='11';
   liEdit.SubItems.ValueFromIndex[0]:='22';
   liEdit.SubItems.ValueFromIndex[1]:='33';
...

this should do what I want, but after this, the values of the subitems are this ones '=22' and '=33' I don't want the equal character to be added.

Can anyone help me? I don't know if this is the right way to edit/update a listitem

thanks

+3  A: 

You could try the following :

with LvProcess.Items[1] do
begin
  Caption := '11';
  SubItems.Strings[0] := '22';
  SubItems.Strings[1] := '33';
end;

And if you're updating many items at once it is better to surround the update in a way like this:

try
  lvProcess.Items.BeginUpdate;

  //Do your updates
finally
  lvProcess.Items.EndUpdate;
end;
Aldo
thanks, I forgot about SubItems.Strings :)
Remus Rigo
A: 

SubItems is a TStrings, so if you want to update the string values, do so like this:

SubItems[0] := '22'
SubItems[1] := '33'

The way you're doing it now, you're using the TStrings as Key/Value list. That's a nice feature of TStrings when you want it, but probably not what you intend.

Larry Lustig