如果说你只想打印DATAGRID中的内容,那不行,只能打印页面,我说的是在WEB中的,如果在WINFORM是可以的,代码:
用IE的打印就行了

解决方案 »

  1.   

    能够具体说明一下再winform下打印datagrid里面的内容是怎么操作的吗?
    顺便说明一下在web下的情况?
      

  2.   

    http://www.redfocus.net/forums/dispbbs.asp?boardID=6&ID=691
      

  3.   

    没有必要打印datagrid中的内容,可以把datagrid的内容转换到,excel,让客户自己打印,
    可以在csdn上搜索一下相关的帖子,应该好解决。
      

  4.   

    上www.codeproject.com看看,有这方面的内容。
      

  5.   

    我刚写的打印程序,记得给我分数啊, private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
    int wid=0;
    int count = 3;
    int p1=linesPrinted;
    float linesPerPage = 0;
    int x=e.MarginBounds.Left;
    int y=e.MarginBounds.Top+20;
    printFont=dataGrid1.HeaderFont;
    linesPerPage = e.MarginBounds.Height /printFont.GetHeight(e.Graphics) -3;
    Pen blackPen = new Pen(Color.Black, 2);
    for(int b=0;b<ds.Tables[0].Columns.Count;b++)
    {
    wid+=dataGrid1.TableStyles[0].GridColumnStyles[b].Width;
    }

    if(slocation=="dzuo")
    {
    e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,x,y-20); }
    if(slocation=="dzhong")
    {
    e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,e.MarginBounds.Width/2,y-20); }
    if(slocation=="dyou")
    {
    e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,e.MarginBounds.Width,y-20); }
    if(slocation=="xzuo")
    {
    e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,x,e.MarginBounds.Bottom); }
    if(slocation=="xyou")
    {
    e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,e.MarginBounds.Width-30,e.MarginBounds.Bottom); }
    if(slocation=="xzhong")
    {
    e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,e.MarginBounds.Width/2,e.MarginBounds.Bottom); }


    for(int a=0;a<ds.Tables[0].Columns.Count;a++)
    {
    if(columnwidth[a]!=0)
    {
    e.Graphics.DrawString(dataGrid1.TableStyles[0].GridColumnStyles[a].HeaderText, dataGrid1.HeaderFont, Brushes.Black, x, y);
    x=x+(dataGrid1.TableStyles[0].GridColumnStyles[a].Width*e.MarginBounds.Width/wid);

    }
    }
    y+=(int)printFont.GetHeight(e.Graphics);
    x=e.MarginBounds.Left;
    e.Graphics.DrawLine(blackPen,x,y,x+e.MarginBounds.Right,y);
    y+=2;

    while(count < linesPerPage && linesPrinted>=0)
    {
    if(linesPrinted<=linesPerPage)
    {

    for(i1=0;i1<=p1-1;i1++)
    {
    for(int j=0;j<ds.Tables[0].Columns.Count;j++)
    {
    if(columnwidth[j]!=0)
    {
    e.Graphics.DrawString(lines[i1+linshi,j],dataGrid1.HeaderFont,Brushes.Black,x,y);
    x=x+(dataGrid1.TableStyles[0].GridColumnStyles[j].Width*e.MarginBounds.Width/wid);
    }
    }
    x=e.MarginBounds.Left;
    count++;
    y+=(int)printFont.GetHeight(e.Graphics);

    }
    e.HasMorePages=false;
    return;
                        
    }
    else
    {
    for(i1=0;i1<linesPerPage;i1++)
    {
    for(int j=0;j<ds.Tables[0].Columns.Count;j++)
    {   
    if(columnwidth[j]!=0)
    {
    e.Graphics.DrawString(lines[i1+linshi,j],dataGrid1.HeaderFont,Brushes.Black,x,y);
    x=x+(dataGrid1.TableStyles[0].GridColumnStyles[j].Width*e.MarginBounds.Width/wid);
    }
    }
    x=e.MarginBounds.Left;
    count++;
    y+=(int)printFont.GetHeight(e.Graphics);
    linesPrinted--;


    }
    if(linesPrinted>0)
    e.HasMorePages=true;
    linshi=linshi+i1;
    ipages++;
    return;
    } }
    } private void bprint_Click(object sender, System.EventArgs e)
    {
    if(printDialog1.ShowDialog()==DialogResult.OK)
    {
    printDocument1.Print();
    }