?
Solved

List View and VISIBLE PROPERTY:

Posted on 2004-04-26
4
Medium Priority
?
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
p_sie earned 2000 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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

764 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