Help - Search - Members - Calendar
Full Version: Print only selected rows in DBGrid
Fast Reports forum > Fast Reports Products > FastReport 2.xx VCL
hej
Hi

Anyone know an easy way to print selected rows from DBgrids.

Henning
basswar
Create temporary table, insert the PK's iterating on the Grid's SelectedRows property,
and let the report based on the JOIN between the temporary and the displayed dataset.

Regards:Alex
llutti
Hi,

I think the better way to solve this problem is:
- To create an array or a list with all numbers of rows is selected in your dbgrid
- To create a frUserDataset to control the navigation in your array
- In report event onGetValue you can access the row in dbgrid using the array like an index

I had use this way to solve similar problem, but with stringgrid an works fine and faster.

Regards

Luciano
Schreij
I once used the method Alex described unsure.gif

I have a (Client)Dataset showed in de DBGrid.
I show some fields for selection (and there is a field FieldID wich is not shown).
There is also a (ADO) temp table and a sql-string for using in this table (the sql is without the where part)

CODE

procedure TForm1.ButtonPrintClick(Sender: TObject);
var i: Integer;
   S: string;
   BML: TBookmarkList;
begin
BML:= DBGrid1.SelectedRows;
if BML.Count = 0 then //no records
 Abort;
S:= '';
with DBGrid1.DataSource.DataSet do begin
 DisableControls;
 try
  for i:= 0 to BML.Count-1 do begin
   Bookmark:= BML[i];
   S:= S + ', '+FieldByName('FieldID').AsString;
  end;//for
 finally
  EnableControls;
 end;//try-finally
end;//with
Delete(S, 1,1);//delete 1th comma
with DM.AdsTmp do begin
 Close;
 CommandText:= sSQL +
 'AND TheID IN ('+S+') ';
 //ORDER BY ...
 Open;
 //Print AdsTmp
end;
end;


The FastReport part is not so difficult when you have a good SQL, with a field for each showed memo.
pele
But how to this without removing NOT selected rows from dataset ?

I have to print selected rows and just skip/jump/no print other
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.