Click here to Skip to main content
15,918,333 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
" i can't give subtotal label fixed value like
new point (100,100)
because dgv rows changeable size depends in number of rows
how to add subtotal label after dgv rows ?

e.Graphics.DrawString(label51.Text.ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(100, 100), format);


Here is my code:
C#
  e.Graphics.FillRectangle(Brushes.Yellow, new Rectangle(30, height, 60, dataGridView5.Rows[0].Height));
                e.Graphics.DrawRectangle(p, new Rectangle(30, height, 60, dataGridView5.Rows[0].Height));
                e.Graphics.DrawString(dataGridView5.Columns[9].HeaderText.ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Rectangle(30, height, 60, dataGridView5.Rows[0].Height), stringFormat);
int Height1 = 0;
                Height1 = 150;



                while (i < dataGridView5.Rows.Count)
                {
                 

                    if (Height1 > e.MarginBounds.Height)
                    {

                        Height1 = 150;
                        e.HasMorePages = true;
                        return;
                    }
                  

                    Height1 += dataGridView5.Rows[i].Height;

                    e.Graphics.DrawRectangle(p, new Rectangle(30, Height1, 60, dataGridView5.Rows[0].Height));
                    e.Graphics.DrawString(dataGridView5.Rows[i].Cells[9].FormattedValue.ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Rectangle(30, Height1, 60, dataGridView5.Rows[0].Height), stringFormat);

                    i++;

                }
                i = 0;
            }


Here is what i want to get:
product_name || amount || price || total 
----------------------------------------
   clothes        1        45       45
   shoes          2        12       24
----------------------------------------
                         total      69
                         discount    9
                         subtotal   60
Posted
Updated 4-Jan-16 9:34am
v4
Comments
ZurdoDev 4-Jan-16 8:06am    
Use labels. Where are you stuck?
Peter M. Adeeb 4-Jan-16 9:43am    
i want to add total row to print page after dgv tabels
in winforms applications
ZurdoDev 4-Jan-16 9:45am    
OK. So, add it. Where are you stuck?
Peter M. Adeeb 4-Jan-16 9:49am    
i'm using code like that
e.Graphics.DrawString(label51.Text.ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(100, 100), format);

now i want to add sub_total after dgv rows @ last print page only
ZurdoDev 4-Jan-16 9:52am    
1. Please click Improve question and show the relevant code. There are a million ways to do this so you need to show us where you are stuck.
2. If you are using DrawString to print the values why can't you print a subtotal row?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900