Results 1 to 7 of 7

Thread: [RESOLVED] getting subitem values from Listview

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Resolved [RESOLVED] getting subitem values from Listview

    Hi

    I'm very new to VB6 so apologies if this is an obvious question....

    I have a listview that has 4 columns. The first column which has an index of 1 according to the property page, is hidden by having its width set to 0. When the user clicks on a row in the listview, I want to be able to get the values from each of the columns and assign them to variables. But I'm having trouble. Here's my code:

    Code:
    Private Sub lvwAudit_ItemClick(ByVal Item As MSComctlLib.ListItem)
    Dim ind As Integer
    Dim itm As ListItem
    ind = Item.Index
    cmdEditAudit.Enabled = True
    AuditInfoID = lvwAudit.ListItems(ind).SubItems(1)
    AuditCheckDt = lvwAudit.ListItems(ind).SubItems(2)
    AuditNxtChkDt = lvwAudit.ListItems(ind).SubItems(3)
    AuditCmnts = lvwAudit.ListItems(ind).SubItems(4)
    End Sub
    When using this code, the "lvwAudit.ListItems(ind).SubItems(1)" bit gets the value from the second column and misses out the first entirely. The "lvwAudit.ListItems(ind).SubItems(4)" is an invalid property. I tried changing the 1 to 0 to get the value from the hidden column but it says that is an invalid property as well. It's like it ignores the existence of the hidden column altogether!

    Please can anyone tell me where I'm going wrong? Thanks!
    Last edited by Hack; Aug 21st, 2007 at 05:48 AM. Reason: Added RESOLVED to thread title and green resolved checkmark

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: getting subitem values from Listview

    The first column value should be
    Code:
    AuditInfoID = lvwAudit.ListItems(1).text
    or
    Code:
    AuditInfoID = lvwAudit.ListItems(1)
    (1) is the listitem 1.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: getting subitem values from Listview

    Quote Originally Posted by Fazi
    The first column value should be
    Code:
    AuditInfoID = lvwAudit.ListItems(1).text
    or
    Code:
    AuditInfoID = lvwAudit.ListItems(1)
    (1) is the listitem 1.

    Thanks! that works for the first column but when I try to get the value for the second column with

    Code:
    AuditCheckDt = lvwAudit.ListItems(2).Text
    It says "Index out of bounds". How do I get the values from the other columns?

  4. #4
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: getting subitem values from Listview

    the subitems like as you have

    Code:
    AuditInfoID = lvwAudit.ListItems(1).SubItems(1)
    So to ritrive all the raws values,
    you need to use a loop for
    Code:
    dim i as interger
    for i=i to  lvwAudit.ListItems.count
        'code here
    next

  5. #5
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: getting subitem values from Listview

    Quote Originally Posted by obscuregirl
    Thanks! that works for the first column but when I try to get the value for the second column with

    Code:
    AuditCheckDt = lvwAudit.ListItems(2).Text
    It says "Index out of bounds". How do I get the values from the other columns?
    Yes, the second coumn is alwas subitem(1)

    so you dont need the subitems(4). this is what cause the error.coz there is no column for it.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Resolved Re: getting subitem values from Listview

    Thanks for your help Fazi, that's working now!

  7. #7
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: getting subitem values from Listview

    Ok

Posting Permissions

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



Click Here to Expand Forum to Full Width