This document is archived and information here might be outdated.  Recommended version.


ICommandBar.Find Method (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Framework > ESRI.ArcGIS.Framework > Interfaces > IC > ICommandBar Interface > ICommandBar.Find Method
ArcGIS Developer Help

ICommandBar.Find Method

Finds a command on this commandbar.

[Visual Basic .NET]
Public Function Find ( _
    ByVal identifier As Object, _
    [ByVal noRecurse As Boolean] _
) As ICommandItem
[C#]
public ICommandItem Find (
    object identifier,
    bool noRecurse
);

Product Availability

Available with ArcGIS Desktop.

Description

 

identifier is the unique identifier of the item you want to find. For built-in commands and commandbars, use the UID. For VBA macros and UIControls use the name.

noRecurse Use False to do a recursive search for the item; otherwise use True. [Optional]

 

Remarks

Here is the syntax that can be used for identifier for each type of menu or command item that can be on the command bar.

Built-in commands and menus
Use the unique identifier (UID) of the command or menu. The built-in Normal.ArcID module can be used to find the UID's.

 pCommandBar.Find(ArcID.Edit_Menu)
 pCommandBar.Find(ArcID.File_AddData)

Instead of using the ArcID module, you can write your own code to get the UID of the object.    


To find the CLSID, ProgID, and subtype of an ESRI command or menu, refer to the following technical documents:

ArcObjects Developer Help > Technical Documents > ArcMap: Names and IDs of commands and commandbars

ArcObjects Developer Help > Technical Documents > ArcCatalog: Names and IDs of commands and commandbars

Custom VBA menus
Use a string that represents the full name of the custom menu. The name of the menu must include the project or template in which this menu was created.
 pCommandBar.Find("Normal.New Menu")
 pCommandBar.Find("Project.New Menu")
 pCommandBar.Find("Project.New Menu 1")

When you create new menus using the Customize dialog, the first menu you create is named "New Menu", the second menu you create is called "New Menu 1", etc... In the Find method, you need to use the default name of the menu instead of the caption you assigned to it. Here is an example of how custom menu naming works.

If you write code to create a new menu, then the name of that item will be prefixed by the project or template in which the module was located.

UIControls
Use a string that represents the full name of the UIControl. The name of the UIControl must include the project or template in which this UIControl was created.
 pCommandBar.Find("Normal.UIButtonControl1")
 pCommandBar.Find("Project.UIToolControl1")
 pCommandBar.Find("TemplateProject.UICombboxControl1")

Macro Items
Use a string that represents the full name of the VBA macro. The name of the macro must include the name of the VBA project and module in which this macro is located. Only Macros that are placed on a toolbar or menu can be found using CommandBars.Find.
  pCommandBar.Find("Project.NewMacros.Test")
  pCommandBar.Find("Normal.ThisDocument.MyMacro")

Custom commands and menus
Use the unique identifier (UID) of your custom command or menu.
You can create a UID object and set the value of the UID to the CLSID or ProgID of your custom object.
For your custom objects, the ProgID is a string composed of the name of your project used to make the command and the class name of the command.
For example if you have a Visual Basic project called MyCustomTools and there is a class module for your command called cmdMyZoomTool in that project, then the ProgID for this command would be "MyCustomTools.cmdMyZoomTool".
To find the CLSID for this command, you could search the system registry for ProgID. Note, if you have a command that is a subtype then you also have to set the SubType property on IUID to the subtype value.
[C#]

The following code creates an ESRI.ArcGIS.esriSystem.UID object and sets the value of the UID to the CLSID or ProgID of the Save command and then passes that UID into the Find method. Note, if the command is a subtype then you also have to set the Subtype property on IUID to the subtype value.

public void FindCommand(ICommandBar standardBar)
{
    UID saveUid = new UIDClass();
    // Use the CLSID of the Save command
    saveUid.Value = "{119591DB-0255-11D2-8D20-080009EE4E51}";
    // Or you can use the ProgID
    //saveUID.Value = "esriArcMapUI.MxFileMenuItem";
    saveUid.SubType = 3;
    ICommandItem cmdItem = standardBar.Find(saveUid, false);
}
[Visual Basic .NET]

The following code creates an ESRI.ArcGIS.esriSystem.UID object and sets the value of the UID to the CLSID or ProgID of the Save command and then passes that UID into the Find method. Note, if the command is a subtype then you also have to set the Subtype property on IUID to the subtype value.

Public Sub FindCommand(standardBar as ICommandBar)
  Dim saveUID As UID = New UIDClass
  ' Use the CLSID of the Save command
  saveUID.Value = "{119591DB-0255-11D2-8D20-080009EE4E51}"
  ' Or you can use the ProgID
  'saveUID.Value = "esriArcMapUI.MxFileMenuItem"
  saveUID.SubType = 3
 
  Dim cmdItem As ICommandItem = standardBar.Find(saveUID)  
End Sub 
 

See Also

ICommandBar Interface | ICommandItem Interface

.NET Samples

Applying user interface customizations at startup