Open an Attribute Table/Database Table Using a Combo Box From ArcMap

1013
4
08-28-2013 10:02 AM
RobertWard1
New Contributor
I'm new to using the Add-in Controls and Visual Studio.  I am trying to create an application toolbar with a combo box that will open tables.  Of the 4 items, 3 are tables and one is a point feature class, all sourced from an SDE db.  The three tables all have long names and require an alias for simplicity.  I'm having zero luck even getting a combo box populated with the correct tables much less getting them to open.  Can anyone offer some insight?  Thanks for all the help
0 Kudos
4 Replies
LeoDonahue
Occasional Contributor III
Are you stuck on getting the names populated in the combo box?  That seems like the easy part.  You are just declaring int values and giving them a name that you supply to the add method.

int table1 = add("The name of your table");  // * caveat:  this is a Java sample

Doesn't that work?


Here is a complete Java Add-in ComboBox sample for setting a timer to refresh your map at given intervals.

import java.io.IOException;

import java.util.Timer;
import java.util.TimerTask;

import com.esri.arcgis.addins.desktop.ComboBox;
import com.esri.arcgis.controls.HookHelper;
import com.esri.arcgis.controls.IHookHelper;
import com.esri.arcgis.interop.AutomationException;

/**
 * ArcMap Add-in that lets the user specify intervals for the map to refresh.
 * 
 * @author donahuel
 *
 */
public class MapRefreshCBX extends ComboBox{

    /**
     * Called when the combo box is initialized. Subclasses must implement this method
     * to add entries to the combo box using the add() method.
     * 
     * @exception java.io.IOException if there are interop problems.
     * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception.
     */
    @Override
    public void initialize() {
        
        try {
            
            manual = add("Manual Map Refresh");
            thirty = add("30  seconds");
            sixty = add("60  seconds");
            ninety = add("90  seconds");
            onetwenty = add("120 seconds");
            onefifty = add("150 seconds");
            oneeighty = add("180 seconds");
            twoten = add("210 seconds");
            twoforty = add("240 seconds");
            twoseventy = add("270 seconds");
            threehundred = add("300 seconds");
            
            hookHelper = new HookHelper();
            hookHelper.setHookByRef(this.hook.getHook());
            
            timer = new Timer();
            
            select(manual);
            
        } catch (AutomationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Called by system when the edit box is typed into (if editable)
     * 
     * @param editString the String typed into the edit box
     * @exception java.io.IOException if there are interop problems.
     * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception.
     */
    @Override
    public void onEditChange(String arg0) throws IOException, AutomationException {
        
    }

    @Override
    public void onEnter() throws IOException, AutomationException {
        
    }

    /**
     * Called by system when the combo box gets or loses focus
     * 
     * @param setFocus - true when combo box gets focus, false when it loses focus
     * @exception java.io.IOException if there are interop problems.
     * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception.
     */
    @Override
    public void onFocus(boolean arg0) throws IOException, AutomationException {
        
    }

    /**
     * Called by system when a selection changes
     * 
     * @param cookie the item selected
     * @exception java.io.IOException if there are interop problems.
     * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception.
     */
    @Override
    public void onSelChange(int arg0) throws IOException, AutomationException {
        
        isTimerStopped = false;
        
        if(arg0 == manual){
            timer.cancel();
            isTimerStopped = true;
        }
        
        if(arg0 == thirty){
            period = 30000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(arg0 == sixty){
            period = 60000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(arg0 == ninety){
            period = 90000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(arg0 == onetwenty){
            period = 120000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(arg0 == onefifty){
            period = 150000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(arg0 == oneeighty){
            period = 180000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(arg0 == twoten){
            period = 210000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(arg0 == twoforty){
            period = 240000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(arg0 == twoseventy){
            period = 270000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(arg0 == threehundred){
            period = 300000;
            if(isTimerStopped){
                
            } else {
                timer.cancel();
                timer = new Timer();
            }
        }
        
        if(isTimerStopped){
            // don't schedule anything because it will log an error saying the timer is already stopped
        } else {
            timer.scheduleAtFixedRate(new TimerTask()
            {
                @Override
                public void run() {
                    try {
                        hookHelper.getActiveView().refresh();
                    } catch (AutomationException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }, delay, period);
        }

    }

    private int manual;
    private int thirty;
    private int sixty;
    private int ninety;
    private int onetwenty;
    private int onefifty;
    private int oneeighty;
    private int twoten;
    private int twoforty;
    private int twoseventy;
    private int threehundred;
    
    private Timer timer;
    private int delay = 0;
    private int period;
    private boolean isTimerStopped;
    private IHookHelper hookHelper;
}
0 Kudos
RobertWard1
New Contributor
I am now able to get the combo box to populate with names that will not change with the following code:
    Public Sub New()
        Add("TABLE1")
        Add("TABLE2")
        Add("TABLE3")
        Add("TABLE4")
    End Sub
using VB.net

Now I need help on tying my actual tables to the names I have established in the Add context.  3 are tables in the sde db and 1 is a feature class. 

I have looked into ITable, but I do not know how to declare the actual tables as the names established in the combobox.  Do i need to establish workspace first?  Thanks!
0 Kudos
LeoDonahue
Occasional Contributor III
In your combo box select changed, based on the int parameter, open a featureclass or table.

examples abound in the online help: 
http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/0001/0001000001vp000000.htm
0 Kudos
RobertWard1
New Contributor
I'm pretty new at coding, can you please elaborate on your post.  Thus far, my combo box has the names of the 4 tables displaying when it is clicked and dropped down.  How do I go about making the attribute tables open in a separate window from this point?  Thanks again for all the help and I apologize for my lack of knowledge and understanding.  Cheers.
0 Kudos