Results 1 to 10 of 10

Thread: SubItems Count?

  1. #1

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    SubItems Count?

    Yep, thats what i want. I want a function that tells if there is data
    in SubItems(3). I know that there is nothing there, because when
    i try to say lvw1.ListItems(i).SubItems(3) it gives an error.. it
    dosen't exist, apparently, although on some OTHER rows it
    exists. I need to be able to find out how many collums there are
    on a specific row. Help !
    Luke

  2. #2
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    Try this:
    VB Code:
    1. ListView1.ListItems(i).ListSubItems.Count
    oh1mie/Vic


  3. #3
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking SAS Data-warehouse training...

    It is good coding practice to use ListSubItems rather than SubItems.
    I think, if I am not mistaken, that SubItems were there for old OS's and earlier versions of VB. These were left in so older programs would still work. ListSubItems were added to replace subitems...They have more properties: Colors, Fonts, Icons etc.
    If you use ListSubItems instead of SubItems then you can do what oh1me suggested...ListView1.ListItems(n).ListSubItems.COunt...

    Adios,

    Woka

  4. #4

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Ah! Thanks! I'll try this out when my gf stops bitching on the
    phone!

    Have a good one!
    Luke

  5. #5

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    It dosent work. It always returns 3, even though there ISNT a
    3rd colum with data in it.
    Luke

  6. #6
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Add a listview to your form called ListView1, then:
    VB Code:
    1. Private Sub Form_Load()
    2. Dim lvwItem     As ListItem
    3.     With ListView1
    4.     .View = lvwReport
    5.         .ColumnHeaders.Add , , "WOOF"
    6.         .ColumnHeaders.Add , , "Hello"
    7.         .ColumnHeaders.Add , , "Column2"
    8.         .ColumnHeaders.Add , , "Muppet"
    9.     End With
    10.     Set lvwItem = ListView1.ListItems.Add(, , "Hello")
    11.     MsgBox lvwItem.ListSubItems.Count 'Returns 0
    12.     lvwItem.ListSubItems.Add , , "Data1"
    13.     MsgBox lvwItem.ListSubItems.Count 'Returns 1
    14. End Sub
    Returns how many listsubitems you have added....it works...

  7. #7

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Heres the code i'm using.
    VB Code:
    1. For i = 1 To lstMP3s.ListCount - 1 Step 1
    2.   'lstMP3s.ListIndex = i
    3.   x.Filename = lstMP3s.List(i)
    4.   DoEvents
    5.   If cboSearchType.Text = "Artist" Then
    6.    If lvwMP3s.ListItems(lvwMP3s.ListItems.Count).Text = x.Artist And lvwMP3s.ListItems(lvwMP3s.ListItems.Count).ListSubItems(1) = x.Title And lvwMP3s.ListItems(lvwMP3s.ListItems.Count).ListSubItems(2) = x.Album And lvwMP3s.ListItems(lvwMP3s.ListItems.Count).ListSubItems(3) = x.Filename Then
    7.     lvwMP3s.ListItems.Remove lvwMP3s.ListItems.Count
    8.     y = y - 1
    9.    End If
    10.    If InStr(1, UCase(x.Artist), UCase(txtSearch.Text)) <> 0 Then
    11.     y = y + 1
    12.     If lvwMP3s.ListItems(1).Text = "Searching..." Then
    13.      lvwMP3s.Checkboxes = True
    14.      lvwMP3s.ListItems.Clear
    15.     End If
    16.     lvwMP3s.ListItems.Add , , x.Artist
    17.     lvwMP3s.ListItems(y).SubItems(1) = x.Title
    18.     lvwMP3s.ListItems(y).SubItems(2) = x.Album
    19.     lvwMP3s.ListItems(y).SubItems(3) = x.Filename
    20.    End If
    21.   End If
    It dosen't work though. Sometimes it posts the same result
    exactly except for ONE minor difference, the last field, which is
    filename, is entirely empty. I tried lvwMP3s.ListIte
    (y).ListSubItems.Count but it didn't work. I also tried
    lvwMP3s.ListItems(y).SubItems(3) and it didn't work. Can
    someone help me patch up this code so it removes the entry in
    the listview if there is NOTHING in the last field ( 3 )?
    Luke

  8. #8

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    I fixed it. After it's done adding the items, it does this
    VB Code:
    1. On Error Resume Next
    2.  For i = 1 To lvwMP3s.ListItems.Count - 1
    3.   If lvwMP3s.ListItems(i).SubItems(3) = "" Then lvwMP3s.ListItems.Remove i
    4.  Next i
    Which works a charm for me! Thanks for all your replies!
    Luke

  9. #9

  10. #10

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Is it possible to use both SubItems and ListSubItems in
    conjunction wiht one another? It would be a real pain if i ahd to
    convert the whole thing to ListSubItems. And i'd be afraid to. The
    code in this program is very delicate. Much more delicate than
    one would think.
    Luke

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