Results 1 to 13 of 13

Thread: Urgent ListView problem - Unresolved

Threaded View

  1. #1

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718

    Urgent ListView problem - Unresolved

    Hi all...

    Here is some code which I use to print and align listviews in the package...

    VB Code:
    1. Option Explicit
    2.  
    3. Public Event MaxYReached(ByVal CurrentY As Double, ByRef oPrinter As Object, ByRef bRePrintHeader As Boolean)
    4. Public Event Progress(ByVal oNextListItem As ListItem, ByRef oPrinter As Object, ByRef bRePrintHeader As Boolean, ByVal lTotalLines As Long, ByRef bCancel As Boolean)
    5.  
    6. Private mlFromX                         As Long
    7.  
    8. Public Sub PrintListview(lvListview As ListView, Optional ByVal oPrinter As Object, Optional ByVal bLines As Boolean = False, Optional ByVal bBlackAndWhite As Boolean = True, Optional ByVal MaxY As Double, Optional ByVal lFromX As Long)
    9.     Dim oListItem                       As ListItem
    10.     Dim oSubItem                        As ListSubItem
    11.     Dim oColumnHeader                   As ColumnHeader
    12.     Dim iCounter                        As Integer
    13.     Dim lPrevY                          As Long
    14.     Dim sCorrectPrintText               As String
    15.     Dim bRePrintHeader                  As Boolean
    16.     Dim bCancel                         As Boolean
    17.    
    18.     mlFromX = lFromX
    19.    
    20.     If oPrinter Is Nothing Then
    21.         Set oPrinter = Printer
    22.     End If
    23.    
    24.     With oPrinter
    25.         .Font = lvListview.Font
    26.         Call PrintHeader(lvListview, oPrinter)
    27.    
    28.         .CurrentY = .CurrentY + .TextHeight(" ") + (.TextHeight(" ") / 2)
    29.         For Each oListItem In lvListview.ListItems
    30.             bRePrintHeader = False
    31.             RaiseEvent Progress(oListItem, oPrinter, bRePrintHeader, lvListview.ListItems.Count, bCancel)
    32.            
    33.             If bCancel Then
    34.                 Exit For
    35.             End If
    36.            
    37.             If bRePrintHeader Then
    38.                 Call PrintHeader(lvListview, oPrinter)
    39.             End If
    40.            
    41.             Set oColumnHeader = lvListview.ColumnHeaders(1)
    42.             lPrevY = .CurrentY
    43.             'oPrinter.Line (.CurrentX, .CurrentY)-(.CurrentX + oListItem.Width, .CurrentY)
    44.             .CurrentY = lPrevY
    45.             .CurrentX = .CurrentX - oListItem.Width
    46.            
    47.             Select Case oColumnHeader.Alignment
    48.                 Case lvwColumnLeft
    49.                     .CurrentX = mlFromX + oListItem.Left + 60
    50.                 Case lvwColumnRight
    51.                     .CurrentX = mlFromX + oListItem.Left + oListItem.Width - .TextWidth(oColumnHeader.Text) - 120
    52.                 Case lvwColumnCenter
    53.                     .CurrentX = mlFromX + oListItem.Left + ((oListItem.Width - .TextWidth(oListItem.Text)) / 2)
    54.             End Select
    55.            
    56.             .ForeColor = IIf(bBlackAndWhite, vbBlack, oListItem.ForeColor)
    57.            
    58.             If oListItem.Width > 15 Then
    59.                 sCorrectPrintText = Trim$(oListItem.Text)
    60.                
    61.                 If .TextWidth(sCorrectPrintText) > oColumnHeader.Width - 60 Then
    62.                     Do Until Not .TextWidth(sCorrectPrintText & "...") > (oColumnHeader.Width - 120)
    63.                         sCorrectPrintText = Mid$(sCorrectPrintText, 1, Len(sCorrectPrintText) - 1)
    64.                     Loop
    65.                    
    66.                     sCorrectPrintText = sCorrectPrintText & "..."
    67.                 End If
    68.                
    69.                 Debug.Assert sCorrectPrintText = Trim$(oListItem.Text)
    70.                 oPrinter.Print sCorrectPrintText;       'Because of some weird bug there has to be oPrinter before this
    71.                                                         ' If i dont add the oPrinter i get a syntax error
    72.             End If
    73.            
    74.             .CurrentY = lPrevY
    75.            
    76.             For Each oSubItem In oListItem.ListSubItems
    77.                 Set oColumnHeader = lvListview.ColumnHeaders(oSubItem.Index + 1)
    78.                
    79.                 Select Case oColumnHeader.Alignment
    80.                     Case lvwColumnLeft
    81.                         .CurrentX = mlFromX + oColumnHeader.Left + 60
    82.                     Case lvwColumnRight
    83.                         .CurrentX = mlFromX + oColumnHeader.Left + oColumnHeader.Width - .TextWidth(oSubItem.Text) - 120
    84.                     Case lvwColumnCenter
    85.                         .CurrentX = mlFromX + oColumnHeader.Left + ((oColumnHeader.Width - .TextWidth(oSubItem.Text)) / 2)
    86.                 End Select
    87.                
    88.                 .ForeColor = IIf(bBlackAndWhite, vbBlack, oSubItem.ForeColor)
    89.                
    90.                 If oColumnHeader.Width > 15 Then
    91.                     sCorrectPrintText = Trim$(oSubItem.Text)
    92.                    
    93.                     If .TextWidth(sCorrectPrintText) > oColumnHeader.Width - 120 Then
    94.                         Do Until Not .TextWidth(sCorrectPrintText & "...") > (oColumnHeader.Width - 120) Or (sCorrectPrintText = "")
    95.                             sCorrectPrintText = Mid$(sCorrectPrintText, 1, Len(sCorrectPrintText) - 1)
    96.                         Loop
    97.                         sCorrectPrintText = sCorrectPrintText & "..."
    98.                     End If
    99.                    
    100.                     oPrinter.Print sCorrectPrintText;
    101.                 End If
    102.                
    103.                 .CurrentY = lPrevY
    104.             Next
    105.            
    106.             .CurrentY = .CurrentY + oListItem.Height
    107.            
    108.             If .CurrentY > MaxY Then
    109.                 RaiseEvent MaxYReached(.CurrentY, oPrinter, bRePrintHeader)
    110.                 If bRePrintHeader Then
    111.                     Call PrintHeader(lvListview, oPrinter)
    112.                     .CurrentY = .CurrentY + .TextHeight(" ") + (.TextHeight(" ") / 2)
    113.                 End If
    114.             End If
    115.         Next
    116.     End With
    117. End Sub
    118.  
    119.  
    120. Public Sub PrintHeader(lvListview As ListView, oPrinter As Object)
    121.     Dim lPrevY                          As Long
    122.     Dim oColumnHeader                   As ColumnHeader
    123.     Dim sCorrectPrintText               As String
    124.    
    125.     With oPrinter
    126.         For Each oColumnHeader In lvListview.ColumnHeaders
    127.             If oColumnHeader.Width > 60 Then
    128.                 lPrevY = .CurrentY
    129.                
    130.                 Select Case oColumnHeader.Alignment
    131.                     Case lvwColumnLeft
    132.                         .CurrentX = mlFromX + oColumnHeader.Left + 60
    133.                     Case lvwColumnRight
    134.                         .CurrentX = mlFromX + oColumnHeader.Left + oColumnHeader.Width - .TextWidth(oColumnHeader.Text) - 120
    135.                     Case lvwColumnCenter
    136.                         .CurrentX = mlFromX + oColumnHeader.Left + ((oColumnHeader.Width - .TextWidth(oColumnHeader.Text)) / 2)
    137.                 End Select
    138.                
    139.                 .FontUnderline = True
    140.            
    141.                 If oColumnHeader.Width > 15 Then
    142.                     sCorrectPrintText = Trim$(oColumnHeader.Text)
    143.                    
    144.                     If sCorrectPrintText <> "" Then
    145.                         If .TextWidth(sCorrectPrintText) > oColumnHeader.Width - 120 Then
    146.                             Do Until Not .TextWidth(sCorrectPrintText & "...") > (oColumnHeader.Width - 120) Or (sCorrectPrintText = "")
    147.                                 sCorrectPrintText = Mid$(sCorrectPrintText, 1, Len(sCorrectPrintText) - 1)
    148.                             Loop
    149.                            
    150.                             sCorrectPrintText = sCorrectPrintText & "..."
    151.                         End If
    152.                        
    153.                         oPrinter.Print sCorrectPrintText;
    154.                     End If
    155.                 End If
    156.                    
    157.                 .FontUnderline = False
    158.                 .CurrentY = lPrevY
    159.             End If
    160.         Next
    161.     End With
    162. End Sub

    The code works fine, but only for the first page! Once all the data has filled the first page... it goes mad. All other remaining fields print on seperate pages! It needs to stop after a certain amount of data, in order to go over to another page.

    Any quick idea's please, PLEASE?

    Regards,

    Paul.
    Last edited by VisionIT; Feb 13th, 2003 at 05:31 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width