Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm creating a custom tool for arcmap toolbox where user select FeatureLayer in one combobox, and in next combobox user can select a field from selected FeatureLayer. FeatureLayer combobox fills automaticaly from:

...
inputParameter.DataType = (IGPDataType)new GPFeatureLayerTypeClass();
inputParameter.Value = (IGPValue)new GPFeatureLayer();

The problem arises when I need to fill field combobox. I'm not realy sure how to set up its parameters. right now i'm trying something like this:

inputParameter = new GPParameterClass();
inputParameter.Enabled = true;
inputParameter.Name = "FieldTrg";
inputParameter.DisplayName = "Feature Class Fields";
inputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
inputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeRequired;
inputParameter.DataType = (IGPDataType)new GPStringType();
inputParameter.Value = (IGPValue)new GPString();
//inputParameter.AddDependency("FeatureClassTrg");
//IGPFeatureSchema fgs = new GPFeatureSchemaClass();
//fgs.FieldsRule = esriGPSchemaFieldsType.esriGPSchemaFieldsAll;
//inputParameter.Schema = (IGPSchema)fgs

In UpdateParameters function I were able to get fields in selected FeatureLayer/FeatureClass, but I had no idea where and how should I put them back in combobox. Also currently the field 'combobox' isn't really a combobox, but just a string field, so probably GPString isn't corect thing to use as its DataType/Value.

Any help regarding this problem would be appreciated.

share|improve this question
add comment

1 Answer 1

As no one have answered this question then i'll share how i managed this. This is part of content in ParameterInfo method.

            inputParameter = new GPParameterClass();
            inputParameter.Enabled = true;
            inputParameter.Name = "myFeatureClass";
            inputParameter.DisplayName = "Targeted Feature Class";
            inputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
            inputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeRequired;
            inputParameter.DataType = (IGPDataType)new GPFeatureLayerTypeClass();
            inputParameter.Value = (IGPValue)new GPFeatureLayer();

            _FcTrgID = parameterId++;
            parameters.Add(inputParameter);

            //source field
            inputParameter = new GPParameterClass();
            inputParameter.Enabled = true;
            inputParameter.Name = "myFields";
            inputParameter.DisplayName = "Fields in targeted feature class";
            inputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
            inputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeRequired;
            inputParameter.DataType = (IGPDataType)new FieldType();
            inputParameter.Value = (IGPValue)new Field();

            inputParameter.AddDependency("myFeatureClass");
            IGPFeatureSchema trgFS = new GPFeatureSchemaClass();
            trgFS.FieldsRule = esriGPSchemaFieldsType.esriGPSchemaFieldsAll;
            inputParameter.Schema = (IGPSchema)trgFS;

            _FieldTrgID = parameterId++;
            parameters.Add(inputParameter);

And this is par of content in UpdateParameters method

            IGPValue trgParamValue = _GPUtilities.UnpackGPValue(paramvalues.get_Element(_FcTrgID));
            if (trgParamValue.IsEmpty() == false)
            {
                IGPValue tempGPV = new GPFieldInfo();
                IGPParameter3 fieldListParam = (IGPParameter3)paramvalues.get_Element(_FieldTrgID);
                IFeatureClass fc;
                try
                {
                    fc = Helper.getFeatureClass(_GPUtilities, paramvalues, _FcTrgID);
                }
                catch (Exception ex)
                {
                    tempGPV.SetAsText("");
                    _GPUtilities.PackGPValue(tempGPV, fieldListParam);
                    return;
                }
                IFields fields = fc.Fields;

                if (previousTrgFc == fc.AliasName)
                    return;
                previousTrgFc = fc.AliasName;
            }

When ever user change selected FeatureLayer then Field combobox is being refreshed with content of last selected featureLayer fields.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.