如何打印的DataGridView单排

编程入门 行业动态 更新时间:2024-10-23 15:29:14
本文介绍了如何打印的DataGridView单排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,我一直在寻找这种帮助周并没有得到尚未答案在这里我去...我有一个DataGridView,这DGV有一个名为ColumnCheckBox(打印)和其他3列是(数目,描述和价格)当我通过在ColumnCheckBox(打印),单击我想从点击打印按钮提及。而这3列获取该行的价值选择一行将打印他们中的每一个,只有选择行!所有的家伙我的搜索运行以创建从阵列中的和打印后,但我不知道怎么办!

Hi guys I've been looking for this help for weeks and didn't get yet the answer here I go...I have a datagridview , this DGV has a ColumnCheckBox named ("print") and other 3 Columns being (Number,Description,Price) When I Select a Row by clicking in the ColumnCheckBox("Print") I want to get the value of the row from this 3 columns mentioned .and by clicking on print button it will print each one of them only the selected row! guys all my searches runs to create an array and after print from the array but i don't know how !

每一个答案,将尝试与AP preciated

every answer will be tried and appreciated

推荐答案

此方式,您可以使用一些标准,发现一排,例如,你可以找到你首先检查行:

This way you can find a row using some criteria, for example you can find your first checked row:

var firstCheckedRow = this.myDataGridView.Rows.Cast<DataGridViewRow>() .Where(row => (bool?)row.Cells["MyCheckBoxColumn"].Value == true) .FirstOrDefault();

这样你就可以得到一个行的所有单元格的值,例如你可以把主题一起在一个字符串中的不同行:

This way you can get value of all cells of a row, for example you can put theme together in a string in different lines:

var builder = new StringBuilder(); firstCheckedRow.Cells.Cast<DataGridViewCell>() .ToList().ForEach(cell => { builder.AppendLine(string.Format("{0}", cell.Value)); });

然后就可以例如告诉他们:

Then you can for example show them:

MessageBox.Show(builder.ToString());

MessageBox.Show(builder.ToString());

甚至你可以把的PrintDocument 表单上,处理的PrintPage 事件来把它们打印到打印机。你还应该把按钮的形式和按钮的点击事件,调用 PrintDocument1.Print();

Or even you can put a PrintDocument on your form and handle PrintPage event to print them to printer. You also should put a Button on form and in click event of button, call PrintDocument1.Print();

code:

private void Button1_Click(object sender, EventArgs e) { PrintDocument1.Print(); } PrintDocument1_PrintPage(object sender, PrintPageEventArgs e) { var firstCheckedRow = this.myDataGridView.Rows.Cast<DataGridViewRow>() .Where(row => (bool?)row.Cells["MyCheckBoxColumn"].Value == true) .FirstOrDefault(); var builder = new StringBuilder(); firstCheckedRow.Cells.Cast<DataGridViewCell>() .ToList().ForEach(cell => { builder.AppendLine(string.Format("{0}", cell.Value)); }); e.Graphics.DrawString(builder.ToString(), this.myDataGridView.Font, new SolidBrush(this.myDataGridView.ForeColor), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); }

更多推荐

如何打印的DataGridView单排

本文发布于:2023-11-30 00:50:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648175.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单排   DataGridView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!