Results 1 to 6 of 6

Thread: ADO and Listview **RESOLVED**

  1. #1
    Hyperactive Member
    Join Date
    Jul 03
    Posts
    419

    ADO and Listview **RESOLVED**

    Hello, I have a database in ADO. I want to populate a listview with every record in the database. The listview will only have 3 columns with headers "field1", "field2", "field3". Each "field" will contain the data from the fields, of the same name in the database. In other words, Column "Field1" will have data from the field in the database "Field1". I did a search and did not really find what I needed.
    Last edited by LostAngel; Dec 16th, 2003 at 12:59 AM.
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  2. #2
    Hyperactive Member
    Join Date
    Jul 03
    Posts
    419
    Anyone know?
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  3. #3
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174
    What code do you have so far to start with? Or something you found?

  4. #4
    Hyperactive Member
    Join Date
    Jul 03
    Posts
    419
    When my form loads, it calls the following.
    VB Code:
    1. If Adodc1.Recordset.BOF = False Then
    2. Adodc1.Recordset.MoveFirst
    3. End If
    4.     List1.Clear                                  'clears list so it makes a new one and does not just add cars
    5.    Do While Adodc1.Recordset.EOF = False                        'do it unless its eof
    6.      
    7.    
    8.             List1.AddItem Adodc1.Recordset!PartName             'adds the 'partname' field
    9.        
    10.     Adodc1.Recordset.MoveNext
    11.     Loop                                        'loops around

    That uses the listbox, I would like to change it to a listview. As you can see though, this will only add the field "PartName". I know how to add new columns on a listview, but wanted to know how to populate each column from a different field in a record. Sort of like what the above code does, but for each of the three fields.
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  5. #5
    PowerPoster lintz's Avatar
    Join Date
    Mar 03
    Location
    The 19th Hole
    Posts
    2,697
    To create the ListView columns use:
    VB Code:
    1. ListView1.View = lvwReport
    2. Set clmX = ListView1.ColumnHeaders.Add(1, , "Field1", 1000)
    3. Set clmX = ListView1.ColumnHeaders.Add(2, , "Field2", 1000)
    4. Set clmX = ListView1.ColumnHeaders.Add(3, , "Field3", 1000)

    Then to populate use:

    VB Code:
    1. If Adodc1.Recordset.BOF = False Then
    2. Adodc1.Recordset.MoveFirst
    3. End If
    4. ListView1.ListItems.Clear  
    5. Do While Adodc1.Recordset.EOF = False      
    6. Set itmX = ListView1.ListItems.Add
    7. itmX = Adodc1!Field1
    8. itmX.SubItems(1) = Adodc1!Field2
    9. itmX.SubItems(2) = Adodc1!Field3
    10. Adodc1.Recordset.MoveNext
    11. Loop

  6. #6
    Hyperactive Member
    Join Date
    Jul 03
    Posts
    419
    Thanks for the code, earlier tonite I managed to figure it out, though my internet was down so I could not put resolved on my topic.
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

Posting Permissions

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