-
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?
-
Weird, it seems to work with very large numbers. i tried "10000000000" and it worked.
-
I thinhk you sould add a special text character at the beginning strkey.
I always use "key" : strkey = "key" & cstr(22222).
-
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.
-
Sorry lads, looks like I messed-up again!
Still, who cares!:)
-
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.
-
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.
-
Well thats the way variants work.
Thats why variants suck, but i guess its is the only way to accept strings/numbers.
-
The same thing happens with the treeview. To get around it I used npminh's method.
-
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!