Select to view content in your preferred language

Addin combobox not releasing focus

2504
1
09-04-2012 10:05 AM
by Anonymous User
Not applicable
Original User: kjweaver

In ArcMap 10, I have an addin combobox on a tool bar. Once the user selects an option from the combobox, a Windows form opens to enable them to enter some information based on their selection.

However, the focus does not shift to the Windows form but stays on the combobox.  I've tried using both .Show() and .ShowDialog() to display the form.  .Show() allows the combobox drop-down to close but the focus remains on the combobox control.  I've also tried forcing the focus to the Windows form in the tool's OnSelChange event and in the form's Load/Activate/Shown events.

My question is: how do I signal to the addin combobox control that it should complete and release focus?  If this were a traditional ITool combobox, I would use the esriSystemUI.ICompletionNotify technique to send a completed message.  The addin combobox seems to have very few Methods/Events available.

How do I release the tool so I can reset the focus to the Windows form (or anywhere else)?
0 Kudos
1 Reply
by Anonymous User
Not applicable
Original User: kjweaver

I consider this a "hack", but here's how I solved the problem to make the addin combobox behave the way I wanted.  With this, the Windows Form opens and has focus and the combobox closes, clears, and loses focus.  Also the combobox contents are only computed once (my combobox contains many conditional items from SQL table queries so it is not practical to requery for the contents every time the combobox gets focus, etc.)

 Public g_sComboValue as String = ""  ' global public variable used to pass selection to Windows form frmMyWinForm

 Public Class MyCombo_Tool
    Inherits ESRI.ArcGIS.Desktop.AddIns.ComboBox

 Private Shared aLayers As New List(Of String)

 Public Sub New()
    GetComboData()    ' private sub that fills aLayers() with the contents to put in the combo, but does not fill the combobox. 
' Code for this sub is not included in this example, but basically can be as simple as aLayers.Add("Item1") . . . 
 End Sub

 Protected Overrides Sub OnSelChange(ByVal cookie As Integer)
        ' Exit if no item chosen from combobox
        If cookie = -1 Then
            Exit Sub
        Else
            g_sComboValue = myComboBox.Value  ' grab the selection to pass to the next form
            Call FillCombo()   ' FillCombo clears and refills the combo to clear the previous selection displayed in the editbox
        End If
 End Sub


 Protected Overrides Sub OnUpdate()
        Enabled = My.ArcMap.Application IsNot Nothing

        If g_sComboValue <> "" Then
            myComboBox.Finalize()
        End If
 End Sub


 Protected Overrides Sub Finalize()
        frmMyWinForm= New frmMyWinForm
        frmMyWinForm.ShowDialog()
        g_sComboValue = ""
 End Sub


 Private Sub FillCombo()
        ' fill combobox from array list
        Dim n As Integer = aLayers.Count
        Dim i As Integer = 0

        myComboBox.Clear()
        For i = 0 To n - 1
            myComboBox.Add(aLayers(i))
        Next i

 End Sub
0 Kudos