Link to home
Start Free TrialLog in
Avatar of QC20N
QC20NFlag for Denmark

asked on

How to add in listview

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

How do I do that?
Avatar of ThievingSix
ThievingSix
Flag of United States of America image


  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

Avatar of QC20N

ASKER

And if I have more than 1 row. How do I add text to the next row?

  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

Avatar of QC20N

ASKER

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.  
Avatar of QC20N

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of ThievingSix
ThievingSix
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of QC20N

ASKER

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.
Avatar of QC20N

ASKER

Please, you have any input to this?
Avatar of QC20N

ASKER

Tried to add 1 more column and added 1 more SubItem.add. Now it works.

Avatar of QC20N

ASKER

Btw, how do I avoid that you can't edit the columns?