ListView Controls Don’t Accept Numeric Keys

ListView Controls Don’t Accept Numeric Keys

In a collection object, such as the ListItems collection from the ListView control, or simply a generic VBcollection object, you can specify a key to uniquely identify the item. Documentation states the key can beany String expression. What if the key needs to be a numerical string? In a ListView control, you might notset a numeric key. Even if you try to set a key equal to Str$(), you’ll receive an error message. Whendisplaying the results of a recordset with a ListView, the key would be the perfect place to hold the primarykey for the row, if applicable. Because ListView doesn’t have an ItemData property, the key is the onlyplace to hold it. The solution is simple: append the string “key” to your Numeric Key, and use the Valfunction to retrieve its value:

 Set itemX = lvPeople.ListItems.Add_        (, , strName)'Set the KeyitemX.Key = Str$(rstPeople!PersonID) _        & "key"        Use this code to retrieve the key:lKey = Val(lvPeople.ListItems_        (nIndex).Key))
See also  Comparing different methods of testing your Infrastructure-as-Code

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist