我用quickreport,想在dbgrid里选择几条记录打印,不知怎么实现,请高手指点。

解决方案 »

  1.   

    你的这种情况不是不可以实现,不过比较麻烦,也就是说不能直接把记录集给quickreport,也就是不知道到底要打印几行,那么只能用程序去写,一行一行的去附值,还要控制下一页打印等等。
    建议:你可以直接把要打印的东西用sql查出来给dbgrid显示,然后直接把记录指针给QR打印,
    如果你一定要选择打印,那还有个小动作,那就是点打印的时候重新生成sql语句,把他附给QR!!
      

  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.   

    有一个方法可以实现:DBGrid有一个允许多项选定的属性参数,设为True之后可以配合键盘进行多项选择,选完之后对数据表进行遍历,标记出选定的记录(假设有一个字段用于标记使用),之后用Tquery的select就可以了,where条件也就简单了,标记字段可以是布尔类型的。