E
Eltonjoanis
Guest
I need to get the checked rows values and print them (2 rows per page sequentially ordered like in the gridview) till print all checked rows it works fine
in this code below but I need to load this list from datagridview and the values from each checked row!
List<string> CheckedValues = new List<string>();
private void button1_Click(object sender, EventArgs e)
{
CheckedValues = new List<string> { "value1", "value2", "value5", "value8", "value10", "value11" };
printDocument1.Print();
}
int currentPrintingIndex = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Width of output labels
var d= this.printDocument1.DefaultPageSettings.PrintableArea.Width / 2;
//Print first output label
if (CheckedValues.Count > currentPrintingIndex)
{
var currentValue = CheckedValues[currentPrintingIndex];
e.Graphics.DrawString(currentValue.ToString(),
this.Font,
new SolidBrush(this.ForeColor),
new RectangleF(
0,
0,
d,
this.printDocument1.DefaultPageSettings.PrintableArea.Height));
currentPrintingIndex += 1;
}
//Print second output label
if (CheckedValues.Count > currentPrintingIndex)
{
var currentValue = CheckedValues[currentPrintingIndex];
e.Graphics.DrawString(currentValue.ToString(),
this.Font,
new SolidBrush(this.ForeColor),
new RectangleF(
d,
0,
d,
this.printDocument1.DefaultPageSettings.PrintableArea.Height));
currentPrintingIndex += 1;
}
//If there is more item to print, go to next page
e.HasMorePages = CheckedValues.Count > currentPrintingIndex;
Continue reading...