Printing Issue in Gridview.

  • Thread starter Thread starter Jparv
  • Start date Start date
J

Jparv

Guest
Hello

I am using this code for creating Items Price,quantity calculation.

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.ColumnIndex == 2 || e.ColumnIndex == 3)
{
// int DISCOUNT;
double cell1 = Convert.ToSingle(dataGridView1.CurrentRow.Cells[2].Value);

double cell2 = Convert.ToSingle(dataGridView1.CurrentRow.Cells[3].Value);

if (cell1.ToString() != "" && cell2.ToString() != "")
{
//dataGridView1.CurrentRow.Cells
dataGridView1.CurrentRow.Cells[4].Value = cell1 * cell2;

}
}
label1.Visible = true;
decimal tot = 0;
for (int i = 0; i <= dataGridView1.RowCount - 1; i++)
{
tot += Convert.ToDecimal(dataGridView1.Rows.Cells[4].Value);
}
if (tot == 0)
{
//MessageBox.Show("No Records Found");
}
txt_netamount.Text = tot.ToString("0.00");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

And priting using this code:

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, 50, 650);

after printing am getting this grid in image format so it reduces the print quality.How to print only rows and columns.?

47334470efaf7c5b21c3d490eb944f76._.png


Continue reading...
 
Back
Top