How may I add additional data for each existing item in a `TListView`?

瘦欲@ 提交于 2020-01-24 23:09:22

问题


I'm working with TListView and I have successfully populated each item's caption and first subitem. See example below.

user   pass   working status  valid 
data1  pass   ---               ---
data2  pass2 ----              -----
-
-
-

After populating each item, I acquire additional data for each item. I want to add this data to populate each item's 'working', 'status', and 'valid' columns. How may I add this additional data for each item?

Each time I have tried, it appears the data is being stored in new items and displayed below the original items. See example below.

user   pass   working status  valid 
data1  pass   ---               ---
data2  pass2 ----              -----
       yes   2009
       no 

How may I add additional data for each existing item in a TListView?


回答1:


I'm not sure I understand the question either.

If you want the columns to be visible, you will need to add columns in the object inspector. (I guess you've already done this).

When you are adding listview items, your code will be something like;

MyItem:=ListView1.Items.Add;
MyItem.Caption:='data1';
for i:=0 to 2 do // this is number of desired subcolumns -1
  MyItem.SubItems.Add(''); // puts blank string in each cell

// then put your data in;
MyItem.SubItems[0]:='pass';
MyItem.SubItems[1]:='---';
MyItem.SubItems[2]:='--'
//etc



回答2:


How are you updating the existing items?

It should be something like:

ListView1.Items[0].SubItems[1] := 'Yes';
ListView1.Items[0].SubItems[2] := '2009';
ListView1.Items[1].SubItems[1] := 'No';


来源:https://stackoverflow.com/questions/1692350/how-may-i-add-additional-data-for-each-existing-item-in-a-tlistview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!