打印列表视图C# [英] Printing a listview C#
问题描述
大家好,
我创建了一家餐厅POS,我在使用listview打印时出现问题
目标是在收据中打印以下
产品数量单价总计
我通过编码管理打印它,但我有另一个问题
使用以下代码
Hello all,
I've created a restaurant POS and i'm having trouble with the listview printing
the target is to print in the receipt the following
Product Quantity Unit Price Total
I've managed through coding to print it, but I have another problem
using the following code
graphics.DrawString(" " + listView1.Items[0].SubItems[0].Text + " " + listView1.Items[0].SubItems[1].Text + " " + listView1.Items[2].SubItems[0].Text + " " + listView1.Items[0].SubItems[3].Text, new Font("Arial Bold", 11),
new SolidBrush(Color.Black), startX, startY + Offset);
问题是,这只是打印列表视图的一行
我尝试添加以前代码的多行以便能够打印6行
但是当任何行为空时它会出错
如何使它在列表视图中动态打印所有项目和子项目,具体取决于用户添加的行数?
我尝试过:
这里是完整的打印代码
the problem is, this only prints one row of the listview
I've tried add multiple lines of the previous code to be able to print 6 rows
but it give an error when any of the rows are empty
how to make it print all items and subitems in a listview dynamically depending on the number of rows add by the user?
What I have tried:
here is the full code of the printing
graphics.DrawString(" " + listView1.Items[0].SubItems[0].Text + " " + listView1.Items[0].SubItems[1].Text + " " + listView1.Items[2].SubItems[0].Text + " " + listView1.Items[0].SubItems[3].Text, new Font("Arial Bold", 11),
new SolidBrush(Color.Black), startX, startY + Offset);
推荐答案
我们已经在评论中已经想到了这一点,但为了完整性,这里的代码是
As we've already figured this out in comments etc, but for completeness, here's the code
for (int i = 0; i < listView1.Items.Count; i++)
{
// Not sure what/why these two are here
int ii = 1;
ii++;
// Draw the row details for ? receipt
graphics.DrawString(" " + listView1.Items[i].SubItems[0].Text + listView1.Items[i].SubItems[1].Text +
listView1.Items[i].SubItems[2].Text + listView1.Items[i].SubItems[3].Text, new Font("Arial Bold", 11),
new SolidBrush(Color.Black), startX, startY + Offset);
// Move the next print position 'down the page' ie, y axis increases from top to bottom
Offset = Offset + 20;
}
这篇关于打印列表视图C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!