Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i want to print datagridview from right to left
most classes in internet print datagridview from left to right
i try to make RightToLeft property to Yes but no change and datagridview printed from left to right
can any one help me
thanks
Posted
Updated 27-Feb-18 18:32pm

Hi,

if you couldn't do it . i will send you my complete code that printing from right to left
1- replace the code that drawing columns with this code.
C#
//Draw Columns                 
for (int i = GridViewID.Columns.Count - 1; i >= 0; i--)
                                {
                                    e.Graphics.FillRectangle(new SolidBrush(Color.LightGray),
                                     new Rectangle((int)arrColumnLefts[iCount], iTopMargin,
                                     (int)arrColumnWidths[iCount], iHeaderHeight));

                                    e.Graphics.DrawRectangle(Pens.Black,
                                        new Rectangle((int)arrColumnLefts[iCount], iTopMargin,
                                        (int)arrColumnWidths[iCount], iHeaderHeight));

                                    e.Graphics.DrawString("  " + GridViewID.Columns[i].HeaderText, GridViewID.Columns[i].InheritedStyle.Font,
                                        new SolidBrush(GridViewID.Columns[i].InheritedStyle.ForeColor),
                                        new RectangleF((int)arrColumnLefts[iCount], iTopMargin,
                                        (int)arrColumnWidths[iCount], iHeaderHeight), strFormat);
                                    iCount++;

                                }




2- replace the code that drawing cells with this code
C#
//Draw Columns Contents
for (int i = GridRow.Cells.Count - 1; i >= 0; i--)
                            {
                                if (GridRow.Cells[i].Value != null)
                                {
                                    e.Graphics.DrawString("  " + GridRow.Cells[i].Value.ToString(), GridRow.Cells[i].InheritedStyle.Font,
                                                new SolidBrush(GridRow.Cells[i].InheritedStyle.ForeColor),
                                                new RectangleF((int)arrColumnLefts[iCount], (float)iTopMargin,
                                                (int)arrColumnWidths[iCount], (float)iCellHeight), strFormat);
                                }
                                //Drawing Cells Borders
                                e.Graphics.DrawRectangle(Pens.Black, new Rectangle((int)arrColumnLefts[iCount],
                                        iTopMargin, (int)arrColumnWidths[iCount], iCellHeight));

                                iCount++;
                            }


Wish that could helps you.

Regards,
A.Mandour
 
Share this answer
 
Think you could just set the Flowdirection="RightToLeft":
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.aspx[^]

But you proberbly need to fix the alignement on the individual cells:
http://stackoverflow.com/questions/4177668/changing-flowdirection-of-a-cell-in-wpfs-datagrid[^]
 
Share this answer
 
This may help you...
Click Here
 
Share this answer
 
Comments
shimaa010 22-Sep-12 4:09am    
thanks for help but this example using vb and i used c#
Please go through Another DataGridView Printer[^]. Download the PDF Files[^]. You will get everything there. Also play with the source codes in the article.

Also check How to RTL print a Datagridview.?[^] for the correct solutions as per your requirements.

Thanks...
 
Share this answer
 

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