[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

List View and VISIBLE PROPERTY:

Posted on 2004-04-26
4
Medium Priority
?
421 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

Independent Software Vendors: 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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