Adding items to listbox in report mode

Hi,

Could anyone tell me how I would go about adding a string/stringlist to a listbox's column in report mode? Is there a different way to do this with the JVCL listbox?

Thanks.
 - MelchaS
MelchaSAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

esoftbgCommented:
listbox's column is not a particular container for TStrings .... ListBox contains only one container for TStrings and it is the property Items. The Columns property specifies the number of columns that are visible without having to horizontally scroll the list box. So different Columns (0, 1, 2 ....) will change the visualization of the ListBox Items (they will be wrapped on Columns > 0)

var
  S:      string
begin
  S := 'some text';
  ListBox1.Items.Add(S); // adds a string into ListBox1
end;


The next procedure assigns the content of a StringList into the ListBox and sets the number of Columns:

procedure AddStringListToListBox(LB: TListBox; SL: TStringList; ColCnt: Integer);
begin
  LB.Columns := ColCnt;
  LB.Items.Assign(SL);
end;
0
MelchaSAuthor Commented:
Sorry, I meant listview. Could you give me an example with that?
0
esoftbgCommented:
procedure AddStringListToListView(SL1: TStringList; SL2: TStringList);
var
  I:      Integer;
  ListItm:TListItem;
begin
  if (SL1.Count=SL2.Count) then
  for I := 0 to SL1.Items.Count-1 do
  begin
    with ListView1 do
    begin
      ListItm := ListView1.Items.Add;
      ListView1.ListItm.Caption := SL1[I];
      ListView1.ListItm.SubItems.Add(SL2[I]);
    end;
  end;
end;

Just from head (not tested)
Emil
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

MelchaSAuthor Commented:
Doesn't work... the listview is a jvlistview in report mode, i want to know how i can add a stringlist and a single string under a specific column..

this is my code:
procedure TForm1.Button1Click(Sender: TObject);
var
      I:      Integer;
      ListItm : TListItem;
      StrL : TStringList;
begin
      try
            StrL := TStringList.Create;
            NFTP.Host := 'Ftp.someftp';
            NFTP.Port := 21;
            NFTP.Connect(TRUE,60);
            logger.Active := TRUE;
            NFTP.List(StrL);
             for I := 0 to StrL.Items.Count-1 do
      begin
            with jvListView1 do
            begin
                  ListItm := jvListView1.Items.Add;
                  jvListView1.ListItm.Caption := StrL[I];
                  jvListView1.ListItm.SubItems.Add(StrL[I]);
            end;
      end;    
      finally
            StrL.Free;
      end;
end;


Errors:

[Error] Unit1.pas(75): Undeclared identifier: 'Items'
[Error] Unit1.pas(80): Undeclared identifier: 'ListItm'
[Error] Unit1.pas(81): Undeclared identifier: 'ListItm'
0
esoftbgCommented:
procedure TForm1.FormCreate(Sender: TObject);
var
  LstCol: TListColumn;
begin
  LstCol := jvListView1.Columns.Add;
  LstCol.Caption := 'FTP';
  LstCol.Width := 128;
  LstCol := jvListView1.Columns.Add;
  LstCol.Caption := 'HH:mm:ss';
  LstCol.Width := 80;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  I:      Integer;
  StrL:   TStringList;
begin
  StrL := TStringList.Create;
  try
    NFTP.Host := 'Ftp.someftp';
    NFTP.Port := 21;
    NFTP.Connect(TRUE,60);
    logger.Active := TRUE;
    NFTP.List(StrL);
    for I := 0 to StrL.Count-1 do
    begin
      jvListView1.Items.Add;
      jvListView1.Items[I].Caption := StrL[I];
      jvListView1.Items[I].SubItems.Add(FormatDateTime('HH:mm:ss', Now));
    end;
  finally
    StrL.Free;
  end;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MelchaSAuthor Commented:
Thanks, that works.
0
esoftbgCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.