Link to home
Start Free TrialLog in
Avatar of MelchaS
MelchaS

asked on

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
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

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;
Avatar of MelchaS
MelchaS

ASKER

Sorry, I meant listview. Could you give me an example with that?
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
Avatar of MelchaS

ASKER

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'
ASKER CERTIFIED SOLUTION
Avatar of esoftbg
esoftbg
Flag of Bulgaria 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 MelchaS

ASKER

Thanks, that works.
You are welcome.