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

Datagridview Printing issue

$
0
0

Hello,

I have a datagridview that I am trying to print, I have set up a print preview dialog so I can see what the print out looks like beforehand.



Above is the headers from my datagridview that I have pulled to be printed.

What i want to achieve is this, I want the columns above to be populated from my datagridview, this is my code so far:

            

Graphics graphic = e.Graphics;

            Font font = new Font("Courier New", 10);
            Pen p = new Pen(Brushes.Black, 2f);

            float fontheight = font.GetHeight();

            int startX = 10;
            int startY = 10;

            //Headers
            graphic.DrawString("Cheque Total: " + totalbox.Text, new Font("Courier New",12),new SolidBrush(Color.Black),startX, startY);
            graphic.DrawString("Supplier: " + dgv2.Rows[0].Cells[0].FormattedValue, new Font("Courier New",12),new SolidBrush(Color.Black),400,startY);
            graphic.DrawString("Payment Date: " + dgv2.Rows[5].Cells[5].FormattedValue, new Font("Courier New", 12), new SolidBrush(Color.Black), startX, startY+30);
            graphic.DrawString("Account Number: " + dgv2.Rows[3].Cells[3].FormattedValue, new Font("Courier New", 12), new SolidBrush(Color.Black), 400, startY+30);
            graphic.DrawString("Cheque Number: " + dgv2.Rows[1].Cells[1].FormattedValue, new Font("Courier New", 12), new SolidBrush(Color.Black), startX, startY+60);

            //Table Column Headers
            graphic.DrawString(dgv2.Columns[2].HeaderText.ToString(), new Font("Courier New", 12), new SolidBrush(Color.Black), startX, 120);
            graphic.DrawString(dgv2.Columns[4].HeaderText.ToString(), new Font("Courier New", 12), new SolidBrush(Color.Black), startX+120, 120);
            graphic.DrawString(dgv2.Columns[6].HeaderText.ToString(), new Font("Courier New", 12), new SolidBrush(Color.Black), startX+350, 120);
            graphic.DrawString(dgv2.Columns[7].HeaderText.ToString(), new Font("Courier New", 12), new SolidBrush(Color.Black), startX+520, 120);

            //Table Values

All of this is in my datagridview, I want to fill the printpage with the cell values of each column, any help will be appreciated.

Thanks

brendan 


Viewing all articles
Browse latest Browse all 2535

Trending Articles



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