Version

Key Property (RowLayout)

Returns or sets a value that uniquely identifies an object in a collection.
Syntax
'Declaration
 
Public Overrides ReadOnly Property Key As String
public override string Key {get;}
Remarks

The Key property is a unique, user-defined object identification string that can be used interchangeably with the Index of an object when accessing it through code. If you attempt to assign a value to the Key property is not unique in the collection, an error will occur.

The value of the Index property of an object can change when objects in the collection are reordered, such as when you add or remove objects. If you expect the Index property to change dynamically, refer to objects in a collection using the Key property. In addition, you can use the Key property to make your program "self-documenting" by assigning meaningful names to the objects in a collection.

You can set the Key property when you use the Add method to add an object to a collection. In some instances, the Key property of an object may be blank if that object does not appear in a collection.

Also, note that the uniqueness of keys is only enforced when the Key property is set to a value. If a collection supports objects with blank keys, that collection may contain multiple objects that whose Key property is empty. In that case, you must use Index property to differentiate between the objects that have blank keys.

Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also