Results 1 to 2 of 2

Thread: List View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

    List View

    how do i add data to a listview. I want to be able to reference it using the selecteditem method to be able to get the data out of it. The listview is in report mode and has three colums, server, game and port.

    I need to be able to fill all three columns with stuff, and have an index.

    how ??

  2. #2
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    Add Method (ListItems, ColumnHeaders), ListItems Property, SubItems Property Example

    The following example uses the Biblio.mdb database as a source to populate a ListView control with ListItem objects. To try this example, place a ListView control on a form and paste the code into the Declarations section. You must also be sure that the Biblio.mdb has been installed on your machine. In the code below, check the path in the OpenDatabase function and change it to reflect the actual path to Biblio.mdb on your machine.

    Note The example will not run unless you add a reference to the Microsoft DAO 3.5 Object Library. To do this, on the Project menu click References. Search for Microsoft DAO 3.5 Object Library and click the checkbox to select it.

    VB Code:
    1. Private Sub Form_Load()
    2.    ' Add ColumnHeaders. The width of the columns is
    3.    ' the width of the control divided by the number of
    4.    ' ColumnHeader objects.
    5.    ListView1.ColumnHeaders. _
    6.    Add , , "Author", ListView1.Width / 3
    7.    ListView1.ColumnHeaders. _
    8.    Add , , "Author ID", ListView1.Width / 3, _
    9.    lvwColumnCenter
    10.    ListView1.ColumnHeaders. _
    11.    Add , , "Birthdate", ListView1.Width / 3
    12.    ' Set View property to Report.
    13.    ListView1.View = lvwReport
    14.  
    15.    ' Declare object variables for the
    16.    ' Data Access objects.
    17.    Dim myDb As Database, myRs As Recordset
    18.    ' Set the Database to the BIBLIO.MDB database.
    19.    ' IMPORTANT: the Biblio.mdb must be on your
    20.    ' machine, and you must set the correct path to
    21.    ' the file in the OpenDatabase function below.
    22.    Set myDb =    DBEngine.Workspaces(0) _
    23.       .OpenDatabase("c:\Program Files\VB\BIBLIO.MDB")
    24.    ' Set the recordset to the "Authors" table.
    25.    Set myRs = _
    26.    myDb.OpenRecordset("Authors", dbOpenDynaset)
    27.    
    28.    ' Declare a variable to add ListItem objects.
    29.    Dim itmX As ListItem
    30.  
    31.    ' While the record is not the last record,
    32.    ' add a ListItem object. Use the author field for
    33.    ' the ListItem object's text. Use the AuthorID
    34.    ' field for the ListItem object's SubItem(1).
    35.    ' Use the "Year of Birth" field for the ListItem
    36.    ' object's SubItem(2).
    37.  
    38.    While Not myRs.EOF
    39.       Set itmX = ListView1.ListItems. _
    40.       Add(, , CStr(myRs!Author))   ' Author.
    41.      
    42.       ' If the AuthorID field is not null, then set
    43.       ' SubItem 1 to it.
    44.       If Not IsNull(myRs!Au_id) Then
    45.          itmX.SubItems(1) = CStr(myRs!Au_id)
    46.       End If
    47.  
    48.       ' If the birth field is not Null, set
    49.       ' SubItem 2 to it.
    50.       If Not IsNull(myRs![Year Born]) Then
    51.          itmX.SubItems(2) = myRs![Year Born]
    52.       End If
    53.       myRs.MoveNext   ' Move to next record.
    54.    Wend
    55. End Sub

    Regards...
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

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