Print Flex Grid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stroumfs
    New Member
    • Mar 2007
    • 28

    #1

    Print Flex Grid

    Hi!

    Can anyone tell me how can i print a flex grid?
    I created a button print below the flex grid.What code should i write in order to print?
    and how can i can i change the colour and the font of some specific cells?
    For example in my flex grid i would like to change the colour in the column(2,1) until (2,10) also in the (4,1) until (4,10), (6,1)until(6,10 ).


    Also can someone help me to write the code below using a for loop
    frmResult.flgPr intingResults.s et_ColWidth(0, 2800)
    frmResult.flgPr intingResults.s et_ColWidth(2, 2800)
    frmResult.flgPr intingResults.s et_ColWidth(4, 2800)
    frmResult.flgPr intingResults.s et_ColWidth(6, 2800)
    frmResult.flgPr intingResults.s et_ColWidth(8, 2800)

    thnks
  • cmrhema
    Contributor
    • Jan 2007
    • 375

    #2
    Actually I got this when I was searching for printing a grid long time back. But I did not try it. Check out and let me know

    Private Sub PrintFlexGrid(B yVal ptr As Object, ByVal flx As _
    MSFlexGrid, ByVal xmin As Single, ByVal ymin As Single)
    Const GAP = 60

    Dim xmax As Single
    Dim ymax As Single
    Dim X As Single
    Dim c As Integer
    Dim r As Integer

    With ptr.Font
    .Name = flxData.Font.Na me
    .Size = flxData.Font.Si ze
    End With

    With flxData
    ' See how wide the whole thing is.
    xmax = xmin + GAP
    For c = 0 To .Cols - 1
    xmax = xmax + .ColWidth(c) + 2 * GAP
    Next c

    ' Print each row.
    ptr.CurrentY = ymin
    For r = 0 To .Rows - 1
    ' Draw a line above this row.
    If r > 0 Then ptr.Line (xmin, _
    ptr.CurrentY)-(xmax, ptr.CurrentY)
    ptr.CurrentY = ptr.CurrentY + GAP

    ' Print the entries on this row.
    X = xmin + GAP
    For c = 0 To .Cols - 1
    ptr.CurrentX = X
    ptr.Print BoundedText(ptr , .TextMatrix(r, _
    c), .ColWidth(c));
    X = X + .ColWidth(c) + 2 * GAP
    Next c
    ptr.CurrentY = ptr.CurrentY + GAP

    ' Move to the next line.
    ptr.Print
    Next r
    ymax = ptr.CurrentY

    ' Draw a box around everything.
    ptr.Line (xmin, ymin)-(xmax, ymax), , B

    ' Draw lines between the columns.
    X = xmin
    For c = 0 To .Cols - 2
    X = X + .ColWidth(c) + 2 * GAP
    ptr.Line (X, ymin)-(X, ymax)
    Next c
    End With
    End Sub

    ' Truncate the string so it fits within the width.
    Private Function BoundedText(ByV al ptr As Object, ByVal txt _
    As String, ByVal max_wid As Single) As String
    Do While ptr.TextWidth(t xt) > max_wid
    txt = Left$(txt, Len(txt) - 1)
    Loop
    BoundedText = txt
    End Function

    Comment

    Working...