Board index » delphi » listview on qreport

listview on qreport

How can we print listview on qreport? It would be nice to have an example
program or source code.

Thank you,
Reid

 

Re:listview on qreport


Assuming you have a TListView with Viewstyle property set to vsReport :-)
-----------------------------------------
Lets say that theres a procedure (CreateLabels) in your  report from
(TFrmListViewReport)
put *qrctrls * in your uses clause, trap the OnNeedData and BeforePrint
events of the report (say QuickRep1)

and keep some variables in the var section:
--------------------------------------

{implementaion section starts here}

var
   lvReport : TlistView;
   LabelList : TList;
   ilvItem,   iMaxSubItemCount,  iRow    : Integer;

procedure TFrmListViewReport.CreateLabels(lv : TListView)
var
   i : Integer;
   alabel : TQRLabel;
   iPosLeft, iLabelWidth : Integer;
begin
    lvReport := lv; {// lv is your listview reference in
TFrmListViewReport}
    iMaxSubItemCount := 0;
    for i := 0 to lvReport.Items.Count-1 do
    if iMaxSubItemCount < lvReport.Items[0].SubItems.Count then
      iMaxSubItemCount := lvReport.Items[0].SubItems.Count;

   iLabelWidth := DetailBand1.Width div (iMaxSubItemCount + 2
+((iMaxSubItemCount-1)*2)  );
 { // This is to set the labels at equal distances.
      //  2 is for the band clearance and (iMaxSubItemCount-1)*2
       //  is for clearance between 2 adjacent labels}

   iPosLeft := 2;
   for i := 1 to iMaxSubItemCount+1 do
   begin
     aLabel := TQRLabel.Create(nil);
     aLabel.Left := iPosLeft;
     aLabel.AutoSize := False;
     aLabel.Width := iLabelWidth;
     aLabel.Parent := DetailBand1; {// detailband1 is your detailband on the
TQuickrep}
     aLabel.Caption := '';
     LabelList.Add(aLabel);
     iPosLeft := iPosLeft + iLabelWidth + 2;
   end;
   end;

procedure TFrmListViewReport.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
   iRow := 0;
end;

procedure TFrmListViewReport.Quickrep1NeedData(sender : TObject; var
MoreData:Boolean);
var
 i : Integer;
begin
  if iRow < lvReport.Items.Count then
  begin
    TQRLabel(LabelList.Items[0]).Caption := lvReport.Items[iRow].Caption;
    for i := 0 to iMaxSubItemCount-1 do
    begin
        if i < lv.Items[iRow].SubItems.Count then
           TQRLabel(LabelList.Items[i+1]).Caption :=
lvReport.Items[iRow].SubItems[i]
       else
          TQRLabel(LabelList.Items[i+1]).Caption := '';
    end;
    MoreData := True;
 end
 else
     MoreData := False;
 Inc(iRow);
end;

{// ah don't forget }
TFrmListViewReport.FormCreate(Sender: TObject);
begin
  LabelList := TList.Create;
end;

procedure TFrmListViewReport.FormClose(Sender: TObject; var Action:
TCloseAction);
var
 i : Integer;
begin
  for i := 0 to LabelList.Count-1 do
  begin
    TQRLabel(LabelList.Items[i]).Free;
  end;
  LabelList.Free;
end;

end.

BINGO!  untested though. High chances of getting *list index out of bounds*
error :-)
anyways,
regards/angshu

Quote
Reid <rsi...@networld.com> wrote in message news:3a1322ee$1_2@dnews...
> How can we print listview on qreport? It would be nice to have an example
> program or source code.

> Thank you,
> Reid

Other Threads