Print only selected rows in DBGrid

hejhej
edited December 2003 in FastReport 2.xx VCL
Hi

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

Henning

Comments

  • edited 8:01PM
    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
  • edited 8:01PM
    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
  • edited 8:01PM
    I once used the method Alex described ;)

    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)
    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.
  • edited June 2010
    But how to this without removing NOT selected rows from dataset ?

    I have to print selected rows and just skip/jump/no print other

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.