I have datagridview which is displaying teh data from database .
I want take a print of that complete data .
My code is :
private void button3_Click(object sender, EventArgs e)
{
PrintDialog printDialog = new PrintDialog();
printDialog.ShowDialog();
printDialog1.AllowSomePages = true;
printDialog1.ShowHelp = true;
printDialog1.Document = docToPrint;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
this.printDocument1.Print();
}
}
private void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
string text = "In document_PrintPage method.";
System.Drawing.Font printFont = new System.Drawing.Font
("Arial", 35, System.Drawing.FontStyle.Regular);
e.Graphics.DrawString(text, printFont,
System.Drawing.Brushes.Black, 10, 10);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCheckBoxCell chkcell = dataGridView1[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
if (chkcell != null)
{
columnsToPrint[dataGridView1.CurrentRow.Index] = Convert.ToBoolean(chkcell.EditedFormattedValue);
}
if (dataGridView1.RowCount > 5)
{
dataGridView1.AllowUserToAddRows = false;
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap bm = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height);
dataGridView1.DrawToBitmap(bm, new Rectangle(0, 0, this.dataGridView1.Width, this.dataGridView1.Height));
e.Graphics.DrawImage(bm, 0, 0);
}
This code is working but it will display only the screenshot type means data that is visible at current size.....not the whole one.
pls reply
meenakshi