O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Store Arbitrary Data in a Control

Problem

You want to link a piece of data to a control.

Solution

Use the Control.Tag property.

Discussion

Every class that derives from System.Windows.Forms.Control provides a Tag property that can be used to store an instance of any type of object. The Tag property isn’t used by the control or the .NET Framework. Instead, it’s reserved as a convenient storage place for application-specific information. When retrieving data from the Tag property, you’ll need to use the CType function to cast the object from the generic System.Object type to its original type.

Many other classes that are used with .NET controls also provide a Tag property. Notable examples include the ListViewItem and TreeNode classes (which represent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required