What is the best way to implement MRU combo box?

828
7
Jump to solution
01-24-2013 06:18 AM
JasonPike
Occasional Contributor
I'm trying to implement a combobox which manages its collection of items as a most recently used (MRU) list. I need to be able to move an item to the top of the list if it is selected, but I've only found the Add() method which appends to the end of the list. Of course, I can clear the combobox and add the reordered list, but that just seems kludgey to me. Any suggestions?
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
Oh, you're talking about an addin.  I don't think there's any way but to clear the list and add the items back like you said.  As far as I know, the underlying combobox control isn't exposed.  If you were implementing the old style command/toolcontrol then you could expose the underlying combobox and get access to all of its properties and methods.

View solution in original post

0 Kudos
7 Replies
NeilClemmons
Regular Contributor III
You could call Remove or RemoveAt to remove the item from the list then call Insert to add it back at the desired index position.
0 Kudos
JasonPike
Occasional Contributor
You could call Remove or RemoveAt to remove the item from the list then call Insert to add it back at the desired index position.


Yes, that is how I would prefer to do it, but I don't see any of those methods on the ArcGIS interfaces:
IComboBox
IComboBoxHook

Should I be casting to another interface that has those methods?

Thanks,
Jason
0 Kudos
LeoDonahue
Regular Contributor
The docs indicate you should be subclassing this if you want to use it.

http://help.arcgis.com/en/sdk/10.0/java_ao_adf/api/arcobjects/com/esri/arcgis/addins/desktop/ComboBo...

.NET docs say: 
Use this interface to define a custom combo box.


Why not use a .NET combobox?
0 Kudos
NeilClemmons
Regular Contributor III
Oh, you're talking about an addin.  I don't think there's any way but to clear the list and add the items back like you said.  As far as I know, the underlying combobox control isn't exposed.  If you were implementing the old style command/toolcontrol then you could expose the underlying combobox and get access to all of its properties and methods.

View solution in original post

0 Kudos
LeoDonahue
Regular Contributor
Sorry, didn't know you were talking about addins either.

You saw this?  http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/0001/0001000004nw000000.htm
0 Kudos
KenBuja
MVP Honored Contributor
There's also this topic specifically about the Addin combobox.

That topic also contains C# and VB.Net code on implementation


Public Class Combo1
  Inherits ESRI.ArcGIS.Desktop.AddIns.ComboBox
  Public Sub New()
    'Add two items to the combo box.
    Dim o1 As New Point()
    o1.PutCoords(0, 0)
    Dim c1 As Integer = Me.Add("Item1", o1)

    Dim o2 As New Point()
    o2.PutCoords(1, 1)
    Dim c2 As Integer = Me.Add("Item2", o2)

    'Add the application's caption.
    Dim app As ESRI.ArcGIS.Framework.IApplication = TryCast(Me.Hook, ESRI.ArcGIS.Framework.IApplication)
    Me.Add(app.Caption)

    'Add one item then remove
    Dim c3 AsInteger = Me.Add("Item3")
    Me.Remove(c3)

    'Select the second item.
    Me.[Select](c2)
  End Sub
 
  Protected Overloads Overrides Sub OnSelChange(ByVal cookie AsInteger)
    If cookie = -1 Then
      Exit Sub
     End If
    
    'Get the associated object.
    Dim tag As Point = TryCast(Me.GetItem(cookie).Tag, Point)
    If tag IsNot Nothing Then
      System.Windows.Forms.MessageBox.Show((tag.X & ", ") + tag.Y)
    End If
  End Sub
 
  Protected Overloads Overrides Sub OnEnter()
    'Loop through the item collection.
     Fo rEach item As ESRI.ArcGIS.Desktop.AddIns.ComboBox.Item In Me.items
      If Me.Value = item.Caption Then
        Exit Sub
      End If
     Next
     Me.Add(Me.Value)
  End Sub
 
  Protected Overloads Overrides Sub OnEditChange(ByVal editString AsString)
    If String.Compare(editString, "ABC", True) = 0 Then
      System.Windows.Forms.MessageBox.Show("editString is " & Me.Value)
    End If
  End Sub
 
  Protected Overloads Overrides Sub OnFocus(ByVal [set] AsBoolean)
    If [set] Then
      System.Diagnostics.Debug.WriteLine("Get focus.")
    End If
   
    If Not [set] Then
      System.Diagnostics.Debug.WriteLine("Lose focus.")
    End If
  End Sub
 
  Protected Overloads Overrides Sub OnUpdate()
    Me.Enabled = ArcMap.Application Is Not Nothing
  End Sub
End Class


0 Kudos
JasonPike
Occasional Contributor
Thanks, all.

I appreciate the links--they confirm what I had found. It looks like the consensus is that I'll have clear and re-add the list if I want to reorder it. Bummer.
0 Kudos