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

Thread: Adding ListView to Project

  1. #1
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,883

    Adding ListView to Project

    How to add the ListView Library to a project ?

    Cant find it under Components or References yet I have heard the name ListView before (very often)

    Any ideas why I cant find it

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Adding ListView to Project

    Under the progress bar? what version of vb?
    Code:
        Private Sub Form_Load()
            'Add ColumnHeaders.  The Width of the column is
            'the Width of the control divided by the
            'number of ColumnHeader objects.  In this example
            'I will have 3 ColumnHeader objects.
            ListView1.ColumnHeaders.Clear
            ListView1.ColumnHeaders.Add , , "Images", ListView1.Width / 3
            ListView1.ColumnHeaders.Add , , "Channels", ListView1.Width / 3
            ListView1.ColumnHeaders.Add , , "Speed", ListView1.Width / 3
            'Set the Border Property and View Property
            ListView1.BorderStyle = ccFixedSingle
            
            'Now you need to declare the object variables for
            'the Data Access objects.
               
            Dim myRS As New ADODB.Recordset
            Dim mConn As New ADODB.Connection
            'I am using the sample Biblio database
            mConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & App.Path & "\db1.mdb"
             With myRS
                     .CursorLocation = adUseClient
                     .Open "select * from table1", mConn, adOpenDynamic, adLockBatchOptimistic
             End With
            'Now you need to declare a variable to add ListItem objects.
            'This is what Martin was trying to point out to you
            Dim itmX As ListItem
            
            'While the record is not the last record,
            'add a ListItem object.  Use the Author field for
            'the the ListItem object's text.
            'I have also added a couple of subitems even though
            'your attempt did not mention subitems.
            'I have used the AuthorID field for the
            'ListItem object's SubItem(1), and
            'the LitsItem object's "Year of Birth" field for the
            'ListItem object's SubItem(3).
       
            While Not myRS.EOF
             
                Set pic1.DataSource = myRS
                ImageList1.ListImages.Add , Trim(myRS.Fields("speed")), pic1.Picture
                Set pic1.DataSource = Nothing
                'If the AuthorID field is not Null, then set
                'SubItem(2) to it.
            Set itmX = ListView1.ListItems.Add(, , , Trim(myRS.Fields("speed")), Trim(myRS.Fields("speed")))
            
            If Not IsNull(myRS!Speed) Then
                    itmX.SubItems(2) = CStr(myRS!Speed)
           End If
               'If the AuthorID field is not Null, then set
                'SubItem(1) to it
                   If Not IsNull(myRS!Channels) Then
                    itmX.SubItems(1) = CStr(myRS!Channels)
           End If
                
                'If the birth field is not Null, then set
                'SubItem(2) to it.
                myRS.MoveNext
            Wend
            
            Set myRS = Nothing
            Set mConn = Nothing
        End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Adding ListView to Project

    The Control it part of the Windows Common Control Libraries.
    Right click on the toolbox and select components (or Project Menu -> Components)

    Then Controls Tab
    Then Microsoft Windows Common Controls 5.0

    Hope that helps!

  4. #4
    Join Date
    May 2008
    Posts
    224

    Re: Adding ListView to Project

    Quote Originally Posted by George1111
    How to add the ListView Library to a project ?

    Cant find it under Components or References yet I have heard the name ListView before (very often)

    Any ideas why I cant find it

    Thanks
    It is part of the Microsoft windows common controls.

    Right click in the toolbox, select components then controls tab then scroll down the list and look for Microsoft windows common controls. The name will vary depending on what you have installed.

    In my case shows up as "microsoft Windows Common Controls 6.0 (sp4)

  5. #5
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,883

    Re: Adding ListView to Project

    Thanks Guys

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)