Learn how to a build a cloud-first strategyRegister Now

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

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
0
MelchaS
Asked:
MelchaS
  • 4
  • 3
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
MelchaSAuthor Commented:
Thanks, that works.
0
 
esoftbgCommented:
You are welcome.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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