都来指点下吧...datagridview数据循环打印

qin_0 2011-10-19 04:27:41
winform窗体

现在有一个datagridview记录购买的商品信息
商品编号,商品名称,兑换积分(用积分兑换,此列是对应商品需要的积分),商品数量
有的商品分在多行显示

我要遍历datagridview里所有数据,进行打印(打印小票)
找大神帮帮忙,代码帮忙写下

注:这个项目是个c/s的,别人做完了n久后,客户要改功能,我才来公司,之前一直在弄b/s,现在真的晕了。。。
大家帮帮忙

先谢了
...全文
120 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ruanwei1987 2011-10-19
  • 打赏
  • 举报
回复
20分

  
private void PrintReceipt()
{
//printFont = new Font("宋体", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
StandardPrintController spc = new StandardPrintController();
pd.PrintController = spc;
pd.Print();
}



private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
Font printFont = new Font("宋体", 8);
float linesPerPage = 0;
int lineCount = 0;
float lineWidth = ev.MarginBounds.Width ;
RectangleF lineRectangleF = new RectangleF(new PointF(0, 0), new SizeF(lineWidth, printFont.GetHeight(ev.Graphics)));
ev.Graphics.DrawString("《小鸡鸡》", new Font("宋体", 10), Brushes.Black, lineRectangleF, formatTitle);
foreach (DataRow row in Gridview.Rows)
{
ev.Graphics.DrawString(“大鸟鸟”, printFont, Brushes.Black, lineRectangleF, new StringFormat());
}
}
从融不迫 2011-10-19
  • 打赏
  • 举报
回复
呃。。。不太明白,你是不会打印呢,还是不会遍历呢。。。还是两个都不会呢。。。。
qin_0 2011-10-19
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 it_xiaohong 的回复:]

听楼主不停推责任别人做的,感觉好像别人做的自己就不该做样,这种心态哟!唉
[/Quote]
你不知道接别人项目做是最头疼的么.还一点注释都没有.
lx66103567 2011-10-19
  • 打赏
  • 举报
回复
在线学~~~~~~~~~~~~~~~
qin_0 2011-10-19
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 it_xiaohong 的回复:]

听楼主不停推责任别人做的,感觉好像别人做的自己就不该做样,这种心态哟!唉
[/Quote]
我现在就是不爽...
xiaohong 2011-10-19
  • 打赏
  • 举报
回复
听楼主不停推责任别人做的,感觉好像别人做的自己就不该做样,这种心态哟!唉
hudenq 2011-10-19
  • 打赏
  • 举报
回复
在printDocument1_PrintPage事件中
string sd0,sd1,sd2.....;
if(dataGridVistring.Rows.Count > 0 )
for (int i = 0; i<dataGridView1.Rows.Count;i++)
{
string sd0 = dataGridView1.Rows(i).Cells(0).Value.Tostring();
string sd1 = dataGridView1.Rows(i).Cells(1).Value.Tostring();
string sd2 = DataGridView1.Rows(i).Cells(2).Value.Tostring();

........................
}

//然后用e.Graphics.DrawString
StringFormat StrF = new StringFormat();
StrF.Alignment = StringAlignment.Center;//对齐方式

Rectangle drawRect = new Rectangle(x, y, w, h);
e.Graphics.DrawString(sd0, new Font("宋体", 13), new Pen(Color.Black, 10).Brush, drawRect, StrF);
.......................
qin_0 2011-10-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yuex008 的回复:]

帮顶。。。。
[/Quote]
不要帮顶,要帮忙!
yuex008 2011-10-19
  • 打赏
  • 举报
回复
帮顶。。。。
qin_0 2011-10-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 bdmh 的回复:]

水晶报表不就行吗,再不行就找其他第三方的,或者自己操控打印机
[/Quote]
水晶报表,我不会.../流汗+/尴尬
这个项目是要给别人公司用的。自己操控不来
bdmh 2011-10-19
  • 打赏
  • 举报
回复
水晶报表不就行吗,再不行就找其他第三方的,或者自己操控打印机
qin_0 2011-10-19
  • 打赏
  • 举报
回复
在线等。。。
qin_0 2011-10-19
  • 打赏
  • 举报
回复
自己先顶一下

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧