Solved

List View and VISIBLE PROPERTY:

Posted on 2004-04-26
4
413 Views
Last Modified: 2013-12-25
Hi everyone:

I am bringing a table to the list view1, this table has 7 fields, one field is ID. So, I would like to diplay all 6 except ID. But, I want to bring ID, so that I can modify specific record if they click. So, how do I do that?
I tried:

    With ListView1
        .ColumnHeaders.Add(, , "Company").Tag = "Company"
        .ColumnHeaders.Add(, , "Contact").Tag = "Contact"
        .ColumnHeaders.Add(, , "City").Tag = "City"
        .ColumnHeaders.Add(, , "State").Tag = "State"
        .ColumnHeaders.Add(, , "Country").Tag = "Country"
        .ColumnHeaders.Add(, , "Phone").Tag = "Phone"
        .ColumnHeaders.Add(, , "ID").Tag = "ID"
        .ColumnHeaders(1).Alignment = lvwColumnLeft
        .ColumnHeaders(2).Alignment = lvwColumnLeft
        .ColumnHeaders(3).Alignment = lvwColumnLeft
        .ColumnHeaders(4).Alignment = lvwColumnLeft
        .ColumnHeaders(5).Alignment = lvwColumnLeft
        .ColumnHeaders(6).Alignment = lvwColumnLeft
        .ColumnHeaders(6).Alignment = lvwColumnLeft
        .ColumnHeaders(1).Width = .Width / 7
        .ColumnHeaders(2).Width = .Width / 7
        .ColumnHeaders(3).Width = .Width / 7
        .ColumnHeaders(4).Width = .Width / 7
        .ColumnHeaders(5).Width = .Width / 7
        .ColumnHeaders(6).Width = .Width / 7
        .ColumnHeaders(6).Width = .Width / 7

    End With

rs.Open "Select CompanyName, ContactName, City, State, Country, PhoneNumber, ID From TblClients  ORDER BY ID ", cn, adOpenKeyset, adLockOptimistic
    If rs.EOF = False Then
        While Not rs.EOF
            If rs.EOF = False Then
                With ListView1
                    With .ListItems
                        With .Add(, , IIf(IsNull(rs(0)) = False, rs(0), ""))
                            .ListSubItems.Add , , IIf(IsNull(rs(1)) = False, rs(1), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(2)) = False, rs(2), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(3)) = False, rs(3), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(4)) = False, rs(4), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(5)) = False, rs(5), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(6)) = False, rs(6), "")
                        End With
                    End With
                End With
            rs.MoveNext
            Else
                rs.Close
                Exit Sub
            End If
        Wend
    Else
       
    End If
    rs.Close

So, I do not want to display ID field in the listview1 but, I do need this info.

Thank you all
0
Comment
Question by:neonlights
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
p_sie earned 500 total points
ID: 10922128
Put the ID in the Tag in the first column of the listview!

Dim Item as ListItem

rs.Open "Select CompanyName, ContactName, City, State, Country, PhoneNumber, ID From TblClients  ORDER BY ID ", cn, adOpenKeyset, adLockOptimistic
    If rs.EOF = False Then
        While Not rs.EOF
            If rs.EOF = False Then
                With ListView1
                    With .ListItems
                        Set item = .Add(, , IIf(IsNull(rs(0)) = False, rs(0), ""))

                        With   Item                    
                            .Tag = rs(ÏD")         'Put the ID in the Tag of the first column
                            .ListSubItems.Add , , IIf(IsNull(rs(1)) = False, rs(1), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(2)) = False, rs(2), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(3)) = False, rs(3), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(4)) = False, rs(4), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(5)) = False, rs(5), "")
                            .ListSubItems.Add , , IIf(IsNull(rs(6)) = False, rs(6), "")
                        End With
                    End With
                End With
            rs.MoveNext
            Else
                rs.Close
                Exit Sub
            End If
        Wend
    Else
       
    End If
    rs.Close


To get the ID of the selected row:

ID = listview.selectedItem.Tag
0
 

Author Comment

by:neonlights
ID: 10924660
Thanks  very much P_Sie.

0
 
LVL 9

Expert Comment

by:p_sie
ID: 10925725
Your welcome!
0
 
LVL 1

Expert Comment

by:daniellyh
ID: 11194055
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now