This documentation is archived and is not being maintained.

Bindings Property

Visual Studio .NET 2003

Sets or returns the list of keystrokes used to invoke the command.

[Visual Basic .NET]
Public Property Bindings() As Object
[Visual Basic 6]
Property Get Bindings() As Variant
Property Let Bindings( _
   ByVal NewValue As Variant _
HRESULT __stdcall get_Bindings(
   /* [out, retval] */ VARIANT* retVal
HRESULT __stdcall put_Bindings(
   /* [in] */ VARIANT NewValue
public object Bindings {get; set;}
[JScript .NET]
public function get Bindings() : Object
public function set Bindings(
   NewValue : Object


A SafeArray containing the keyboard shortcuts to use.


Bindings sets or returns a SafeArray of strings describing all of the key bindings for the command. You add bindings to the command by adding them to the SafeArray and then setting it back afterwards. You remove bindings from the command by removing them from the SafeArray and then setting it back afterwards.

The syntax of each string is either one of the following (where "modifiers+" is optional):

  • "scopename::modifiers+key"
  • "scopename::modifiers+key, modifiers+key"

Modifiers are "ctrl+", "alt+", and "shift+". They can appear in any order. The first modifier or key specifier immediately follows the double colons ("::"). There is one space after any comma separator in a key sequence.

Everything is reported using mixed case, such as "Ctrl+Space", but you can use any case combination when adding new bindings.

Spaces are handled as literals in the binding string. There are no escapes sequences for space and tab characters, and so forth. Some examples of binding settings are:

  • "Text Editor::ctrl+r, ctrl+r"
  • "Global::ctrl+o"
  • "Global::f2"

Bindings returns Nothing for commands that cannot have bindings, that is, they do not show up in the Tools Options keyboard bindings property page. If you attempt to set this property for such a command, it returns an error.

Note   You cannot programmatically change the settings for the default keyboard mapping scheme. To change the settings, save a copy of the default keyboard mapping scheme in the Keyboard node in the Options dialog box. You can then change the settings in that mapping scheme.


Sub BindingsExample()
   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")

   ' Assigns 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: Command Object