CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Listview and crystal report.

  1. #1
    Join Date
    Jan 2005
    Posts
    70

    Listview and crystal report.

    My test code:

    Code:
    Private Sub Command1_Click()
        Call GetListViewData(ListView1)
    End Sub
    Private Sub Form_Load()
    ' Set listview
        With ListView1
            .View = lvwReport
            .FullRowSelect = True
            .ColumnHeaders.Add , , "Id", 1100
            .ColumnHeaders.Add , , "First Name", 1400
            .ColumnHeaders.Add , , "Last Name", 1400
            .ColumnHeaders.Add , , "Email", 1700
        End With
        ' Insert Data
        With ListView1.ListItems
            .Add , , "1"
            .Item(1).SubItems(1) = "Andre"
            .Item(1).SubItems(2) = "White"
            .Item(1).SubItems(3) = "Andre@White.com"
    
            .Add , , "2"
            .Item(2).SubItems(1) = "Danny"
            .Item(2).SubItems(2) = "Burnett"
            .Item(2).SubItems(3) = "Danny@Burnett.com"
    
            .Add , , "3"
            .Item(3).SubItems(1) = "Edward"
            .Item(3).SubItems(2) = "Carter"
            .Item(3).SubItems(3) = "Edward@Carter.com"
    
            .Add , , "4"
            .Item(4).SubItems(1) = "Anne"
            .Item(4).SubItems(2) = "Witter"
            .Item(4).SubItems(3) = "Anne@Witter.com"
    
            .Add , , "5"
            .Item(5).SubItems(1) = "Vicky"
            .Item(5).SubItems(2) = "Myron"
            .Item(5).SubItems(3) = "Vicky@Myron.com"
        End With
        
    End Sub
    Private Sub GetListViewData(lv As ListView)
    
        Dim I As Integer, rsTest As Recordset
        'Dim DataReport1 As CRAXDRT.Report
        
        Set rsTest = New ADODB.Recordset
        With rsTest.Fields
            .Append "Field1", adBSTR
            .Append "Field2", adBSTR
            .Append "Field3", adBSTR
            .Append "Field4", adBSTR
        End With
        
        rsTest.Open
        
        For I = 1 To lv.ListItems.Count
            With rsTest
                .AddNew
                .Fields("Field1") = lv.ListItems(I).Text
                .Fields("Field2") = lv.ListItems(I).SubItems(1)
                .Fields("Field3") = lv.ListItems(I).SubItems(2)
                .Fields("Field4") = lv.ListItems(I).SubItems(3)
                .Update
            End With
        Next I
        
        Set DataReport1.DataSource = rsTest
          With DataReport1.Sections("Section1") '.Controls
            .Controls("Text1").DataField = "Field1"
            .Controls("Text2").DataField = "Field2"
            .Controls("Text3").DataField = "Field3"
            .Controls("Text4").DataField = "Field4"
        End With
        
        DataReport1.Refresh
        DataReport1.Show 1
    
    End Sub
    I'm confused!

    1) i need a report1 in a dir?
    2) i need to call the report from code before?
    3) the code is and experiment very important
    4) attache if is posible a report based my code.

    Tks,
    Attached Files Attached Files
    Last edited by sal21; May 4th, 2020 at 11:02 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,738

    Re: Listview and crystal report.

    Please, edit your post adding CODE tags and proper indentatios.
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2005
    Posts
    70

    Re: Listview and crystal report.

    Quote Originally Posted by VictorN View Post
    Please, edit your post adding CODE tags and proper indentatios.
    ok sir, But how to?

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,154

    Re: Listview and crystal report.

    Quote Originally Posted by sal21 View Post
    ok sir, But how to?
    I see you figured it out!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.3)

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)