Results 1 to 10 of 10

Thread: ListView listitem key field

  1. #1

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Has anyone ever tried using number as a listitem key?

    You can't do it!

    Even if the number is a string it complains.

    Code:
    Private Sub Command1_Click()
    Dim itmx As ListItem
    Dim strKey  As String
    strKey = CStr(22222)
    
    Set itmx = ListView1.ListItems.Add(, strKey, "Item 1")
    End Sub
    Is there a way around this?
    Mark
    -------------------

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Weird, it seems to work with very large numbers. i tried "10000000000" and it worked.
    Iain, thats with an i by the way!

  3. #3
    Guest
    I thinhk you sould add a special text character at the beginning strkey.
    I always use "key" : strkey = "key" & cstr(22222).

  4. #4

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Well that's one way npminh but it's messy and I shouldn't have to because cstr(22222)is a string and the key need to be a string.

    Mark
    -------------------

  5. #5
    New Member Bill Gates's Avatar
    Join Date
    Mar 2000
    Posts
    7

    Talking

    Sorry lads, looks like I messed-up again!

    Still, who cares!

  6. #6
    Guest
    it is because you can access the items by Index or by Key.
    So it would never know if you where accessing a key or an index.



  7. #7
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Thats just plain dumb.

    If you pass it a string, then it should look for the key.

    The index is a number, so if you pass it a number, it should look for the index.

    Bloody VB.
    Iain, thats with an i by the way!

  8. #8
    Guest
    Well thats the way variants work.
    Thats why variants suck, but i guess its is the only way to accept strings/numbers.

  9. #9
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274
    The same thing happens with the treeview. To get around it I used npminh's method.

  10. #10
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Exclamation Extra Alphabet

    How about just add an extra alphabet infront of the supplied key?

    Code:
    Private Sub Command1_Click()
    Dim itmx As ListItem
    Dim strKey  As String
    strKey = "k" & CStr(22222)
    
    Set itmx = ListView1.ListItems.Add(, strKey, "Item 1")
    End Sub
    I always did that, instead of using integer or long as my key value.

    Hope this will work for you.
    Cheers!

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