Problem solve Get help with specific problems with your technologies, process and projects.

How to add a key to a listview item in VB.NET

How can I add a key to a listview item in VB.NET?
Unfortunately, the ListView control in .NET v1.x doesn't support indexing of its items collection by key. This has been added in .NET v2. For now, you'll have to inherit the control and extend it to support this, by exposing additional methods/properties that work with keyed items. You can for example expose a KeyedItems property where you allow the addition of items with a key. When something is added with a key, you simply store the item in the base class Items collection, but keep the index in a hashtable, for example. The property you expose would have to expose the same interface (plus the keyed members) as the Items one, so you'll probably be better off inheriting from ListView.ListViewItemCollection.
Once you have your custom control (class), it's just a matter of adding it to the toolbox manually or just doing a find-and-replace to change the instances you already have.

Dig Deeper on Win Development Resources

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.