Search code examples
delphitlistview

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


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?


Solution

  • 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