ICommandItem Issue

2732
6
Jump to solution
10-05-2015 09:21 PM
SaurabhGupta5
Occasional Contributor

Hello Everyone,

I am facing small issue in arcobject programming, please help me out from this.

I am using below function to activate editor toolbar

internal void OpenCommandItem(string strUID)

        {

            UID pAttributeEditorUID = new UID();

            pAttributeEditorUID.Value = strUID;

            IMxDocument pmxDoc = ArcMap.Document;

            IDocument pDoc = (IDocument)pmxDoc;

            ICommandBars pCmdBars = pDoc.CommandBars;

            ICommandItem pCommItem = pCmdBars.Find(pAttributeEditorUID, false, false);

            pCommItem.Execute();

            pCommItem.Refresh();          

        }

parameter value is : esriArcMapUI.EditingToolbarCommand

Now, When i am closing the arcmap without closing editor toolbar and next time i use same function to activate it , actually it is hiding toolbar that time. It is only working in scenario when i am closing editor toolbar manually before closing arcmap. Please suggest .

Regards

0 Kudos
1 Solution

Accepted Solutions
SaurabhGupta5
Occasional Contributor

i can able to make out this using

UID uid = new UIDClass();

            uid.Value = "esriEditor.EditingToolbarNew";

            ICommandBar pCI = (ICommandBar)ArcMap.Application.Document.CommandBars.Find(uid, false, false);

            UID id = new UIDClass();

            id.Value = "esriArcMapUI.EditingToolbarCommand";

            ICommandItem ec = (ICommandItem)ArcMap.Application.Document.CommandBars.Find(id, false, false);

            bool visibility = pCI.IsVisible();

            if (!visibility)

                ec.Execute();

still if there is any better way please let me know thanks

View solution in original post

0 Kudos
6 Replies
ModyBuchbinder
Esri Regular Contributor

Hi

Try ((ICommandBar)pCommItem).IsVisible  to show if it is already visible

0 Kudos
SaurabhGupta5
Occasional Contributor

Thanks for quick reply but i am getting following error

Cannot cast 'pCommItem' (which has an actual type of 'System.__ComObject') to 'ESRI.ArcGIS.Framework.ICommandBar'

Regards

Saurabh

0 Kudos
ModyBuchbinder
Esri Regular Contributor

You are getting the command to turn on the toolbar and not the toolbar itself.

You can try something like this

ICommand cmd =  pCommItem.Command

Then check cmd.Checked

Did not tried it but should work

0 Kudos
SaurabhGupta5
Occasional Contributor

Hi Mody,

There is nothing like pCommItem.Command.

Regards

0 Kudos
ModyBuchbinder
Esri Regular Contributor

ICommandItem is your var of type ICommandItem.

This interface have Command property, try get_Command.

0 Kudos
SaurabhGupta5
Occasional Contributor

i can able to make out this using

UID uid = new UIDClass();

            uid.Value = "esriEditor.EditingToolbarNew";

            ICommandBar pCI = (ICommandBar)ArcMap.Application.Document.CommandBars.Find(uid, false, false);

            UID id = new UIDClass();

            id.Value = "esriArcMapUI.EditingToolbarCommand";

            ICommandItem ec = (ICommandItem)ArcMap.Application.Document.CommandBars.Find(id, false, false);

            bool visibility = pCI.IsVisible();

            if (!visibility)

                ec.Execute();

still if there is any better way please let me know thanks

0 Kudos