VS 2008 Combo Box question

1562
3
02-18-2011 03:49 AM
LukeBadgerow
New Contributor
I've been mucking with this for too long, so anyone who wants to slap me about the back of the head with this would be greatly appreciated.

I've got a method that is calling out and returning an object[] of my coded value domain descriptions and I would like to push that to a combo box that is part of a dockable window that is a component of an editor extension add-in that I'm building
        public object[] GetDomainValues(String codedvaluedomain)
        {
            
            IWorkspace ws = (IWorkspace)ArcMap.Editor.EditWorkspace;
            if(ws == null)
            {
                ws = OpenSDEWorkspace("server", "5151", "database", "version", "user", "pass");
            }
            IWorkspaceDomains domains = (IWorkspaceDomains)ws;
            object[] domainobject = null;


                IEnumDomain domainEnum = domains.Domains;
                IDomain domain = domainEnum.Next();
                String name = "";

                while (domain != null)
                {
                    name = domain.Name;
                    domain = domainEnum.Next();
                    if (name.Equals(codedvaluedomain))
                    { 
                        break;
                    }
                }
                ICodedValueDomain codeddomain = new CodedValueDomainClass();
                codeddomain = domains.get_DomainByName(name) as ICodedValueDomain;
                domainobject = new object[codeddomain.CodeCount];

                for (int a = 0; a < codeddomain.CodeCount; a++)
                {
                    object domainvalue = codeddomain.get_Value(a);
                    String domainvaluename = codeddomain.get_Name(a);
                    domainobject.SetValue(domainvaluename, a);
                }
            
            
            return domainobject;
        }


the problem I keep running into is trying to create the entire array as a new object[] on start up/ or at some points even compiling.

I'm attempting to access in this manner:
this.mydomaincombobox.DataSource = this.utils.GetDomainValues(stringcodeddomainname);
0 Kudos
3 Replies
JeffreyHamblin
New Contributor III
Hi Luke,

I tried playing around with your code in a simple button add-in. I got it to work by replacing this line:
IWorkspace ws = (IWorkspace)ArcMap.Editor.EditWorkspace;

with:
// Get a reference to the editor extension
UID uid = new UIDClass();
uid.Value = "esriEditor.Editor";
IEditor editor = ArcMap.Application.FindExtensionByCLSID(uid) as IEditor;

IWorkspace ws = editor.EditWorkspace;


Not sure if it makes a difference that you're working with a dockable window in an editor extension.

Later... Ok, I see that in editor extensions, the ArcMap object has an "Editor" static member. So now I'm not sure why your code doesn't work. I will try to build a test editor extension with a dockable window and see if I make any headway.

-Jeff
0 Kudos
JeffreyHamblin
New Contributor III
I put together a test Add-In with an editor extension and a dockable window.

I refered to the custom selection extension sample for help.

In my testing, your GetDomainValues() method works when passed a valid domain name in the active edit session's workspace (which was a file gdb in my case).

To set the datasource for the combobox, I called a static method in the dockable window class from the extension just before showing the dockable window.

// in MyEditorExtension.cs
MyDockWin.LoadDomainCombobox("DirTypes"); // domain name is known for testing


// in MyDockWin.cs
public partial class MyDockWin : UserControl
{
    private static ComboBox s_comboBoxDomNames = null;
   
    public MyDockWin(object hook)
    {
        InitializeComponent();
        this.Hook = hook;

        s_comboBoxDomNames = this.comboBoxDomNames;
    }

    internal static void LoadDomainCombobox(String codedvaluedomain)
    {
        if (s_comboBoxDomNames != null)
        {
            s_comboBoxDomNames.DataSource = GetDomainValues(codedvaluedomain);
        }
    }

    private static object[] GetDomainValues(String codedvaluedomain)
    //... rest of your function unchanged

    //... rest of boilerplate in class



I hope that is some help.

-Jeff
0 Kudos
LukeBadgerow
New Contributor
Thanks Much Jeff!
0 Kudos