有3种方法:第一、使用printdocument把datagrid中的数据逐行读出,然后写入printdocument中,在写入是根据格式要求在代码中为printdocutment的内容排版,这中方法比较麻烦 但自己可以控制的东西最多~
第二、导出到Excel中去打印~ 方法也是把datagrid中的数据逐行读出,然后写入到Excel中的某个sheet中~ 然后利用Excel本身的打印设置及打印预览功能~
第三、用水晶报表~ 本人觉得水晶报表的打印预览刷新得太差~ 上下滚动时经常花屏~

解决方案 »

  1.   

    if(this.cmgMain.Count!=0)
    {
     Excel._Application excel=new Excel.ApplicationClass();
     excel.Application.Workbooks.Add(true);
     Excel.Worksheet curSheet=(Excel.Worksheet)excel.ActiveSheet;
     curSheet.Cells[2,1]="摘要";
     curSheet.Cells[2,2]="物料";
     curSheet.Cells[2,3]="数量(吨)";
     curSheet.Cells[2,4]="参考价(元/吨)";
     curSheet.Cells[2,5]="金额(元)";
     curSheet.Cells[2,6]="单价(元/吨)";
     curSheet.Cells[2,7]="实收金额(元)";
     curSheet.PageSetup.PrintGridlines=true;
     int startRow=2;
      if(this.cmgDetail.Count!=0)
      {
       startRow++;
       for(int i=0;i<this.cmgDetail.Count;i++)
       {
         this.cmgDetail.Position=i;
         BillDataSet.AccountBookItemRow curDetailRow= ((MIS.WinUI.Purchase.BillDataSet.AccountBookItemRow)
    ((DataRowView)this.cmgDetail.Current).Row);
    }
    curSheet.Cells[startRow,MATERIALCOL+1]=curDetailRow.GoodsList.ToString();
    curSheet.Cells[startRow,AMOUNTCOL+1]=curDetailRow.Amount.ToString();
    curSheet.Cells[startRow,PRICECOL+1]=curDetailRow.Price.ToString();
    curSheet.Cells[startRow,REFMONEYCOL+1]=curDetailRow.RefMoney.ToString();
    curSheet.Cells[startRow,REALPRICECOL+1]=curDetailRow.RealPrice.ToString();
    curSheet.Cells[startRow,MONEYCOL+1]=curDetailRow.Money.ToString();
    startRow++;
    }
    }
    curSheet.Columns.AutoFit();
    excel.Visible=true;
    }
      

  2.   

    xiexie...我用的是水晶报告你的代码我回去研究研究。。结账