This documentation is archived and is not being maintained.

Item Method (Commands Collection)

Visual Studio .NET 2003

Returns an indexed member of a collection.

[Visual Basic .NET]
Public Function Item( _
   ByVal index As Object, _
   Optional ByVal ID As Integer = -1 _
) As Command
[Visual Basic 6]
Function Item( _
   ByVal index As Variant, _
   Optional ByVal ID As Long = -1 _
) As Command
[C++]
HRESULT __stdcall Item(
   VARIANT index,
   long ID,
   /* [out, retval] */ Command** retVal
);
[C#]
public Command Item(
   object index,
   int ID
);
[JScript .NET]
public function Item(
   index : Object,
   ID : int
) : Command

Parameters

index
Required. An absolute index, GUID string, or the command's full name.
ID
Optional. The command ID in the specified command set.

Return Value

Returns a Command object.

Remarks

If index is an absolute index (a Long), it is only meaningful for iterating over the commands from 1 to n. You cannot save a command's absolute index and use it later to access that command.

If index is a GUID string, then it indicates a command set and you must supply the ID argument to identify the command in the set.

If you supply the ID argument and the first argument is a string, then the index argument must be a GUID string that identifies a command set. If index is a string and there is no ID argument, then index must be a command's full name. If index is a Long, then ID is ignored.

Example

Sub ItemExample()
   Dim cmds As Commands
   Dim cmd As Command

   ' Set references to the Commands collection and the File.NewFile 
   ' command.
   cmds = DTE.Commands
   cmd = cmds.Item("File.NewFile")

   ' Assign the command (File.NewFile) globally to the F2 key.
   ' Since you cannot programmatically change the default keyboard mapping 
   ' scheme settings, you must first make a copy of the Default 
   ' Settings for the Keyboard Mapping Scheme.
   cmd.Bindings = "Global::f2"
End Sub

See Also

Applies To: Commands Collection

Show: