Går det överhuvudtaget att printa ut innehållet ur en listview som tex från en listbox????? This subroutine prints the contents of a ListView control in report view. The parameter Lines specifies the number of rows that will be printed, beginning with the first row. If LV.ListCount is less than the parameter Lines, then all the rows will be printed. The columns in the LV control are tabbed to be uniformly distributed across the page. Tack Berätta gärna vad du gjorde för modifieringar och skicka ännu hellre upp det i tips & tricks!!! Som vanligt har jag skrivit om funktionen. För utom optimering har jag laggt till möjlighet för marginaler: Hej Pelle Ok. Tjusigt Andreas - du drar in den i tips & tricks va ;-)Printa ut innehållet i en listview?
Sv: Printa ut innehållet i en listview?
<code>
Public Sub PrintListView(LV As ListView, Lines%)
Dim i%, LVWidth%, NewTab%, j%
Dim itmX As ListItem
Dim LineCount%
LVWidth = 0
For i = 1 To LV.ColumnHeaders.Count
LVWidth = LVWidth + LV.ColumnHeaders(i).Width
Next
NewTab = 0
For i = 1 To LV.ColumnHeaders.Count
NewTab = NewTab + CInt(LV.ColumnHeaders(i).Width * Printer.ScaleWidth / LVWidth)
Printer.Print LV.ColumnHeaders(i).Text;
Printer.CurrentX = NewTab
Next
Printer.Print
If Lines < LV.ListItems.Count And Lines <> 0 Then
LineCount = Lines
Else
LineCount = LV.ListItems.Count
End If
For i = 1 To LineCount
NewTab = 0
Set itmX = LV.ListItems(i)
Printer.Print itmX.Text;
For j = 1 To LV.ColumnHeaders.Count - 1
NewTab = NewTab + CInt(LV.ColumnHeaders(j).Width * Printer.ScaleWidth / LVWidth)
Printer.CurrentX = NewTab
Printer.Print itmX.SubItems(j);
Next
Printer.Print
Next
End Sub
</code>Sv: Printa ut innehållet i en listview?
Har letat länge efter det här, fick det att fungerade efter div små modifieringar.
Mvh
Tobbe
Sv: Printa ut innehållet i en listview?
/PelleSv: Printa ut innehållet i en listview?
Public Sub PrintListView(ListView As ListView, Optional LeftMarginal As Single, Optional TopMarginal As Single, Optional RightMarginal As Single, Optional BottomMarginal As Single)
Dim Index As Long
Dim LVWidth As Long
Dim LastHeader As Long
Dim PrinterWidth As Single
Dim PrinterHeight As Single
Dim ColumnLeft() As Single
Dim ListItem As ListItem
Dim ColumnHeader As ColumnHeader
LVWidth = ColumnWidth(ListView)
LastHeader = ListView.ColumnHeaders.Count - 1
PrinterWidth = Printer.ScaleWidth - LeftMarginal - RightMarginal
PrinterHeight = Printer.ScaleHeight - TopMarginal - BottomMarginal
'Calculate headers position
ReDim ColumnLeft(0 To ListView.ColumnHeaders.Count)
ColumnLeft(0) = Printer.ScaleLeft + LeftMarginal
For Each ColumnHeader In ListView.ColumnHeaders
Index = Index + 1
ColumnLeft(Index) = ColumnLeft(Index - 1) + (ColumnHeader.Width * PrinterWidth \ LVWidth)
Next
'Prints headers on first page
PrintHeaders ListView, TopMarginal, ColumnLeft
For Each ListItem In ListView.ListItems
'Prints headers
If Printer.CurrentY > Printer.ScaleHeight - BottomMarginal Then
Printer.NewPage
PrintHeaders ListView, TopMarginal, ColumnLeft
End If
'Prints lines on page
Printer.CurrentX = ColumnLeft(0)
Printer.Print ListItem.Text;
For Index = 1 To LastHeader
Printer.CurrentX = ColumnLeft(Index)
Printer.Print ListItem.SubItems(Index);
Next
Printer.Print 'New Line
Next
Printer.EndDoc
End Sub
Private Sub PrintHeaders(ListView As ListView, TopMarginal As Single, ColumnLeft() As Single)
Dim Index As Long
Dim ColumnHeader As ColumnHeader
Printer.FontBold = True
Printer.CurrentY = Printer.ScaleTop + TopMarginal
For Each ColumnHeader In ListView.ColumnHeaders
Printer.CurrentX = ColumnLeft(Index)
Printer.Print ColumnHeader.Text;
Index = Index + 1
Next
Printer.Print 'New Line
Printer.FontBold = False
End Sub
Private Function ColumnWidth(ListView As ListView)
Dim ColumnHeader As ColumnHeader
For Each ColumnHeader In ListView.ColumnHeaders
ColumnWidth = ColumnWidth + ColumnHeader.Width
Next
End Function
Exempel på syntax:
Private Sub mnuFilePrint_Click()
PrintListView ListView1, Printer.ScaleX(2, vbCentimeters), Printer.ScaleY(1, vbCentimeters), Printer.ScaleX(1, vbCentimeters), Printer.ScaleY(1, vbCentimeters)
End SubSv: Printa ut innehållet i en listview?
Det jag gorde för att få det att fungera i mitt program var att ändra från Public sub till private sub och så fick ta bort (listview as listview) inga stora ändringar samt lite marginaländringar.
Mvh
TobbeSv: Printa ut innehållet i en listview?
/Pelle