Datagridviewprinter Right to left

Jackson1998

Member
Joined
Jun 1, 2014
Messages
10
Programming Experience
1-3
Hello guys !!

i'm working on a simple project which i need to print a datagridview data out , i used Datagridviewprinter class [Attached below]for the process , it worked fine
but in next step i want to print data from Right to left (for languages start from right to left )

i dont know if someone has worked on this previously , any help will be appreciated

thanks View attachment DataGridViewPrinter.zip
 
If it didn't work then you did it wrong but you haven't shown us what you did so we can't possibly know what's wrong with it. Show us the specific part of the code that you changed and the original so that we can compare and see why it's not working. We're not psychic so you actually have to give us the relevant information.
 
i just changed these loops on part (function )called " Calculate" .

For i = 0 To TheDataGridView.Columns.Count - 1 to ' For i= TheDataGridView.Columns.Count - 1 to 0 step -1 '
also For j=0 to TheDataGridView.Rows.Count - 1 to ' For j= TheDataGridView.Rows.Count - 1 to 0 step -1 '

'
the result when i print : Last cell displayed correctly but previous one disappeared with no rectangles .
the original class code is attached already in main post .

here is the function code :
VB.NET:
Private Sub Calculate(ByVal g As Graphics)        If PageNumber = 0 Then ' Just calculate once
            Dim tmpSize As SizeF = New SizeF()
            Dim tmpFont As Font
            Dim tmpWidth As Single
            Dim i As Integer
            Dim j As Integer
            TheDataGridView.RightToLeft = RightToLeft.Yes
            TheDataGridViewWidth = 0
            For i = 0 To TheDataGridView.Columns.Count - 1
                tmpFont = TheDataGridView.ColumnHeadersDefaultCellStyle.Font
                If tmpFont Is Nothing Then ' If there is no special HeaderFont style, then use the default DataGridView font style
                    tmpFont = TheDataGridView.DefaultCellStyle.Font
                End If
                tmpSize = g.MeasureString(TheDataGridView.Columns(i).HeaderText, tmpFont)
                tmpWidth = tmpSize.Width
                RowHeaderHeight = tmpSize.Height


                For j = 0 To TheDataGridView.Rows.Count - 1
                    tmpFont = TheDataGridView.Rows(j).DefaultCellStyle.Font
                    If tmpFont Is Nothing Then ' If the there is no special font style of the CurrentRow, then use the default one associated with the DataGridView control
                        tmpFont = TheDataGridView.DefaultCellStyle.Font
                    End If


                    tmpSize = g.MeasureString("Anything", tmpFont)
                    RowsHeight.Add(tmpSize.Height)


                    tmpSize = g.MeasureString(TheDataGridView.Rows(j).Cells(i).EditedFormattedValue.ToString(), tmpFont)
                    If (tmpSize.Width > tmpWidth) Then
                        tmpWidth = tmpSize.Width
                    End If
                Next
                If TheDataGridView.Columns(i).Visible Then
                    TheDataGridViewWidth += tmpWidth
                End If
                ColumnsWidth.Add(tmpWidth)
            Next


            ' Define the start/stop column points based on the page width and the DataGridView Width
            ' We will use this to determine the columns which are drawn on each page and how wrapping will be handled
            ' By default, the wrapping will occurr such that the maximum number of columns for a page will be determine
            Dim k As Integer


            Dim mStartPoint As Integer = 0
            For k = TheDataGridView.Columns.Count - 1 To 0 Step -1
                If TheDataGridView.Columns(k).Visible Then
                    mStartPoint = k
                    Exit For
                End If
            Next
            Dim mEndPoint As Integer = TheDataGridView.Columns.Count
            For k = 0 To TheDataGridView.Columns.Count - 1
                If TheDataGridView.Columns(k).Visible Then
                    mEndPoint = k + 1
                    Exit For
                End If
            Next


            Dim mTempWidth As Single = TheDataGridViewWidth
            Dim mTempPrintArea As Single = CType(PageWidth, Single) - CType(LeftMargin, Single) - CType(RightMargin, Single)


            ' We only care about handling where the total datagridview width is bigger then the print area
            If TheDataGridViewWidth > mTempPrintArea Then
                mTempWidth = 0.0
                For k = 0 To TheDataGridView.Columns.Count - 1
                    If TheDataGridView.Columns(k).Visible Then
                        mTempWidth += ColumnsWidth(k)
                        ' If the width is bigger than the page area, then define a new column print range
                        If (mTempWidth > mTempPrintArea) Then
                            mTempWidth -= ColumnsWidth(k)
                            mColumnPoints.Add(New Integer() {mStartPoint, mEndPoint})
                            mColumnPointsWidth.Add(mTempWidth)
                            mStartPoint = k
                            mTempWidth = ColumnsWidth(k)
                        End If
                    End If
                    ' Our end point is actually one index above the current index
                    mEndPoint = k + 1
                Next
            End If
            ' Add the last set of columns
            mColumnPoints.Add(New Integer() {mStartPoint, mEndPoint})
            mColumnPointsWidth.Add(mTempWidth)
            mColumnPoint = 0
        End If
    End Sub
thanks
 
i just changed these loops on part (function )called " Calculate" .

For i = 0 To TheDataGridView.Columns.Count - 1 to ' For i= TheDataGridView.Columns.Count - 1 to 0 step -1 '
also For j=0 to TheDataGridView.Rows.Count - 1 to ' For j= TheDataGridView.Rows.Count - 1 to 0 step -1 '
Right-to-left means reversing the columns but it doesn't change how the rows are accessed. It's not bottom-to-top. Change only the horizontal order but not the vertical.

You should then debug the code, which I'm guessing that you haven't done. Place a breakpoint at the top of the code (F9) and then, when execution breaks, step through the code line by line. You can then determine whether the state of the app is what you expect it to be at each step.
 
i did that , but it still the same result

When you say that you did that do you just mean that you tried reversing the order of one loop or do you mean that you debugged the code?
 
Back
Top