Solved

List View and VISIBLE PROPERTY:

Posted on 2004-04-26
4
414 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

910 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

26 Experts available now in Live!

Get 1:1 Help Now