tartanrug

Setting focus to Tool / Command

Discussion created by tartanrug on Sep 28, 2011
Latest reply on Oct 3, 2011 by dubravko.antonic-gdi-net-esridist
Hi,

I have the following function which works ok when setting the focus to a tool:

   Public Sub CorrectFocus(ByVal p_application As IApplication, ByVal toolname As String)
        Dim pCommand As ESRI.ArcGIS.SystemUI.ICommand
        Dim m_application As IApplication
        Dim curr_tool As String
        curr_tool = toolname
        m_application = p_application
        pCommand = p_application.Document.CommandBars.Find(curr_tool, False, False)
        If pCommand Is Nothing Then
            MsgBox("Could not find tool")
        Else
            m_application.CurrentTool = pCommand
        End If
    End Sub

This works fine when the tool in question (curr_tool) inherits from BaseTool, however I have situations where the 'tool' I need to focus on inherits from BaseCommand and when I carry out the above function in this case, I get an ArgumentException 'Value does not fall in expected range'.

Is there any way I could modify or rewrite the above function so it would re-focus on a tool inheriting from BaseCommand?

Any help appreciated!

Thanks
Simon

Outcomes