Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

How to add in listview

I have 3 columns and I want to add text into them.

How do I do that?
0
QC20N
Asked:
QC20N
  • 7
  • 3
1 Solution
 
ThievingSixCommented:

  ListView1.ViewStyle := vsReport;
  With ListView1.Items.Add Do
    begin
    Caption := 'Column 1';
    SubItems.Add('Column 2');
    SubItems.Add('Column 3');
  end;

Open in new window

0
 
QC20NAuthor Commented:
And if I have more than 1 row. How do I add text to the next row?
0
 
ThievingSixCommented:

  ListView1.ViewStyle := vsReport;
  With ListView1.Items.Add Do
    begin
    Caption := 'Row 1 Column 1';
    SubItems.Add('Row 1 Column 2');
    SubItems.Add('Row 1 Column 3');
  end;
  With ListView1.Items.Add Do
    begin
    Caption := 'Row 2 Column 1';
    SubItems.Add('Row 2 Column 2');
    SubItems.Add('Row 2 Column 3');
  end;

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
QC20NAuthor Commented:
But I have a query an I don't know what the result will be. My query search in an DB for a name. So the name could apear 2 , 3 or 40 times in my DB. So I can't use that solution.  
0
 
QC20NAuthor Commented:
And btw, if I do what you have written. I get the output in the attach file.
            while not ADOQuery1.Eof do
            begin
              Listview1.Items.Add.Caption := ADOQuery1.FieldByName('cn').AsString;
              Listview1.Items.Add.SubItems.Add(ADOQuery1.FieldByName('samAccountName').AsString);
              Listview1.Items.Add.SubItems.Add(copy(ADOQuery1.FieldByName('manager').AsString,4,pos(',',ADOQuery1.FieldByName('manager').AsString)-4));
              ADOQuery1.Next;
            end;

Open in new window

untitled2.JPG
0
 
ThievingSixCommented:
Yea, you implemented it slightly wrong.

Here's a corrected version:
            while not ADOQuery1.Eof do
            begin
              With ListView1.Items.Add Do
                begin
                Caption := ADOQuery1.FieldByName('cn').AsString;
                SubItems.Add(ADOQuery1.FieldByName('samAccountName').AsString);
                SubItems.Add(copy(ADOQuery1.FieldByName('manager').AsString,4,pos(',',ADOQuery1.FieldByName('manager').AsString)-4));
              end;
              ADOQuery1.Next;
            end;

Open in new window

0
 
QC20NAuthor Commented:
Wow. I didn't know there was a different between what you did and I did. But the last Subitems.Add overwrite the 1st Subitems.Add. There is notthing in the 3rd Column.
0
 
QC20NAuthor Commented:
Please, you have any input to this?
0
 
QC20NAuthor Commented:
Tried to add 1 more column and added 1 more SubItem.add. Now it works.

0
 
QC20NAuthor Commented:
Btw, how do I avoid that you can't edit the columns?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now