listview也能做报表呀?小弟刚刚知道,请教相关的知识.我对这个控件一窍不通:-(
它是将报表嵌入到里面还是"画"出来的?如何在上面再放一个"打印"按钮,能实现打印功能?
谢谢.

解决方案 »

  1.   

    http://www.vb-helper.com/howto_listview_print.html
    Private Sub mnuFilePrint_Click()
        Printer.CurrentX = 1440
        Printer.CurrentY = 1440    PrintListView ListView1    Printer.EndDoc
    End SubPrivate Sub PrintListView(lvw As ListView)
    Const MARGIN = 60
    Const COL_MARGIN = 240Dim ymin As Single
    Dim ymax As Single
    Dim xmin As Single
    Dim xmax As Single
    Dim num_cols As Integer
    Dim column_header As ColumnHeader
    Dim list_item As ListItem
    Dim i As Integer
    Dim num_subitems As Integer
    Dim col_wid() As Single
    Dim X As Single
    Dim Y As Single
    Dim line_hgt As Single    xmin = Printer.CurrentX
        ymin = Printer.CurrentY    ' ******************
        ' Get column widths.
        num_cols = lvw.ColumnHeaders.Count
        ReDim col_wid(1 To num_cols)    ' Check the column headers.
        For i = 1 To num_cols
            col_wid(i) = _
                Printer.TextWidth(lvw.ColumnHeaders(i).Text)
        Next i    ' Check the items.
        num_subitems = num_cols - 1
        For Each list_item In lvw.ListItems
            ' Check the item.
            If col_wid(1) < Printer.TextWidth(list_item.Text) _
                Then _
               col_wid(1) = Printer.TextWidth(list_item.Text)        ' Check the subitems.
            For i = 1 To num_subitems
                If col_wid(i + 1) < _
                    Printer.TextWidth(list_item.SubItems(i)) _
                    Then _
                   col_wid(i + 1) = _
                       Printer.TextWidth(list_item.SubItems(i))
            Next i
        Next list_item    ' Add a column margin.
        For i = 1 To num_cols
            col_wid(i) = col_wid(i) + COL_MARGIN
        Next i    ' *************************
        ' Print the column headers.
        Printer.CurrentY = ymin + MARGIN
        Printer.CurrentX = xmin + MARGIN
        X = xmin + MARGIN
        For i = 1 To num_cols
            Printer.CurrentX = X
            Printer.Print FittedText( _
                lvw.ColumnHeaders(i).Text, col_wid(i));
            X = X + col_wid(i)
        Next i
        xmax = X + MARGIN    Printer.Print
        line_hgt = Printer.TextHeight("X")
        Y = Printer.CurrentY + line_hgt / 2
        Printer.Line (xmin, Y)-(xmax, Y)
        Y = Y + line_hgt / 2    ' Print the rows.
        num_subitems = num_cols - 1
        For Each list_item In lvw.ListItems
            X = xmin + MARGIN        ' Print the item.
            Printer.CurrentX = X
            Printer.CurrentY = Y
            Printer.Print FittedText( _
                list_item.Text, col_wid(1));
            X = X + col_wid(1)        ' Print the subitems.
            For i = 1 To num_subitems
                Printer.CurrentX = X
                Printer.Print FittedText( _
                    list_item.SubItems(i), col_wid(i + 1));
                X = X + col_wid(i + 1)
            Next i        Y = Y + line_hgt * 1.5
        Next list_item
        ymax = Y    ' Draw lines around it all.
        Printer.Line (xmin, ymin)-(xmax, ymax), , B    X = xmin + MARGIN / 2
        For i = 1 To num_cols - 1
            X = X + col_wid(i)
            Printer.Line (X, ymin)-(X, ymax)
        Next i
    End Sub' Return as much text as will fit in this width.
    Private Function FittedText(ByVal txt As String, ByVal wid _
        As Single) As String
        Do While Printer.TextWidth(txt) > wid
            txt = Left$(txt, Len(txt) - 1)
        Loop
        FittedText = txt
    End Function
      

  2.   

    VB6中其它报表方法:1、用VB自带的报表工具DataReport2、用excel作报表3、水晶报表或Active Reports
      

  3.   

    当然,你也可以直接操作Print
      

  4.   

    http://www.lihuasoft.net/source/show.php?id=2792
      

  5.   

    洪根哥哥的意思是不是说用listview做报表只能去画了。 不能像用DataReport那样用线来画了?有没有最简便的方法?
      

  6.   

    用报表工具,你就需要另外指一个数据源,而不是指定ListView,如果用ListView,你就写个函数.还要简单的方法?上边的代码,你考过去,直接将ListView传过去不就OK了嘛.