Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Printing Issue in Gridview.

$
0
0

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[i].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.?


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>