我用quickreport,我想在dbgrid里随意选择记录打印,请高手指点一下我该怎么做,明天要到客户那里交货的,在线等待。

解决方案 »

  1.   

    去看frDBDataSet的属性就知道了。
      

  2.   

    StringGrid里的要不要?选择几行就当几行,而且,具体有什么字段也是动态的。procedure TGridcs.SpeedButton2Click(Sender: TObject);
    var
      Form1 : TForm1;
      Col_Value , Top_Value , Row_Value : Integer;
      GridWidth : Integer;
    begin
      Form1 := TForm1.Create(Application);
      OnLine := True;
      Top_Value := 17 ;
      Top_Temp := 17;
      //---------------------------------------------------------------------
      if CheckBox2.Checked then
      begin
        GridWidth := GetGridWidth;
        Top_Value := 17 ;
        Row_Value := 17 ;
        RowScaValue := Row_Sca;
        if Not CheckBox1.Checked then
        begin
          OnLine := False;
          Form1.CreateRowQRShape(Top_Value + 20 + Round(Row_Sca * 17), TextViewGrid.Left,
                                GridWidth, 1);
        end;
        For Col_Value := 0 to FColCount - 1  do
        begin
          Form1.CreateRQLabel(Top_Value + Round(Round(Row_Sca * 17)/2), SetUpHB.Sections[Col_Value].Left,
                              TextViewGrid.ColWidths[Col_Value], 17, Col_Value,SetUpHB.Sections[Col_Value].Text).Show;
        end;
        QRColHeight := Top_Value;
        Inc(Row_Value);
        if Not CheckBox1.Checked then
          Form1.CreateColQRShape(Top_Value - 2 ,GridWidth,1,20 + Round(Row_Sca * 17));
        Top_Value := Top_Value + ( 1 * 20) + Round(Row_Sca * 17);
        Top_Temp := Top_Value;
      end;
      //---------------------------------------------------------------------
      GridWidth := GetGridWidth;
      Top_Value := Top_Temp ;
      Row_Value := FRowMin ;
      RowScaValue := Row_Sca;
      
      While Top_Value <= 718 do
      begin
        if Not CheckBox1.Checked then
        begin
          OnLine := False;
          Form1.CreateRowQRShape(Top_Value + 20 + Round(Row_Sca * 17), TextViewGrid.Left,
                                GridWidth, 1);
        end;
        For Col_Value := 0 to FColCount - 2  do
        begin
          Form1.CreateRQLabel(Top_Value + Round(Round(Row_Sca * 17)/2), SetUpHB.Sections[Col_Value].Left,
                              TextViewGrid.ColWidths[Col_Value], 17, Col_Value,TextViewGrid.Cells
                              [Col_Value,Row_Value]).Show;
        end;
        QRColHeight := Top_Value;
        Inc(Row_Value);
        if Not CheckBox1.Checked then
          Form1.CreateColQRShape(Top_Value - 2 ,GridWidth,1,20 + Round(Row_Sca * 17));
        if Row_Value >= FRowMax then
        begin
          Form1.QuickRep1.Preview;
          Exit;
        end;
        Top_Value := Top_Value + ( 1 * 20) + Round(Row_Sca * 17);
      end;
      Form1.QuickRep1.Preview;
    end;
      

  3.   

    假设你的Quickrep已经设置好了,只要得到当前选择记录打印(即得到数据集)
    // (支持多记录打印)我用的是DBGridEh控件
    procedure TMainForm.PrintFeiMYReport;
    var
      i            : integer;
      BookMarkList : TBookMarkListEh;
      BookMark     : TBookMark;
      strSQL, str  : string;
    begin
      with FQueryForm do
      begin
        BookMark := DSShow.DataSet.GetBookMark;
        strSQL := 'select * from FeiMYFKSBB where LiuSH in ('; //FeiMYFLSBB是表名
                  
            BookMarkList := dbgFeiMY.SelectedRows;   // dbgFeiMY是TDBGridEh类型
            with DSShow.DataSet do
            for i := 0 to BookMarkList.Count - 1 do
            begin
              GotoBookMark(pointer(BookMarkList[i]));
              if i <> BookMarkList.Count - 1 then
                str := str + '''' + fieldbyname('LiuSH').asstring + '''' + ','
              else
                str := str + '''' + fieldbyname('LiuSH').asstring + '''';
            end;
            DSShow.DataSet.GotoBook(BookMark);
            DSShow.DataSet.FreeBooK(BookMark);
        strSQL := strSQL + str + ')  ';
      end;
      if not assigned(FReportForm) then   // FReportForm是报表窗体
        FReportForm:= TFReportForm.Create(application);
      with FReportForm.qryFeiMY do
      begin
        Connection:= Conn.AdoConn;
        Close;           SQL.Clear;
        SQL.Add(strSQL); Open;
      end;
      FReportForm.qrFeiMYD.Preview;
    end;