Select to view content in your preferred language

How to list field names using checkboxes

704
3
03-23-2012 12:31 PM
MarilynGambone
Deactivated User
Hi,

I'm creating a custom tool implementing IGPFunction2 in C#. How do I create an IGPParameterEdit3 object in ParameterInfo that displays the fields of a feature class in checkboxes so a user can select a field?

I have this code snippet for the feature class:

IArray parameters = new ArrayClass();

//0: input_feature
IGPParameterEdit3 input_feature = new GPParameterClass();
input_feature.Name = "input_feature";
input_feature.DisplayName = "Input Feature";
input_feature.DataType = new DEFeatureClassTypeClass() as IGPDataType;
input_feature.Value = new DEFeatureClass() as IGPValue;
input_feature.ParameterType = esriGPParameterType.esriGPParameterRequired;
input_feature.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
parameters.Add(input_feature);

//1: field_name (select one from a list of field names)
//TO DO: get the field names from input_feature and display as checkboxes

Appreciate any help.
0 Kudos
3 Replies
GeorgeFaraj
Frequent Contributor

//TO DO: get the field names from input_feature and display as checkboxes

Appreciate any help.


public static List<string> GetFeatureFields( IFeatureLayer featureLayer ) {
    List<string> fieldList = new List<string>();
    IFeatureClass featureClass = featureLayer.FeatureClass;
    if ( featureClass == null ) return fieldList;
    for ( int x = 0; x < featureClass.Fields.FieldCount; x++ ) {
        IField field = featureClass.Fields.get_Field( x );
        fieldList.Add( field.Name );
    }
    return fieldList;
}
0 Kudos
MarilynGambone
Deactivated User
Hi,

Thanks for the reply.  What I need, however, is the same input-behavior as the Dissolve Tool (Data Management) such that when a user enters a feature class in a textbox, the fields of that feature class "pops up" with checkboxes before it.  I am not using a Windows Form, however.  I'm using the ArcObjects "built-in" window for custom tools (IGPFunction).

It seems like the only way to get to the ArcObjects window is through ParameterInfo.  I don't know what interface to implement to get this checkboxes list.  In Windows Form, we can simply drag CheckedListBox control.  I don't know what's the equivalent of that in ArcObjects.
0 Kudos
NeilEtheridge
Occasional Contributor
Hi Marilyn,

Was just attempting to do the same thing myself and came across your post.  Try this ...

First build a domain of the fields.  In my case I wanted to exclude fields like Raster, Blob, etc.
 
// Field Domain
IGPFieldDomain fieldDomain = new GPFieldDomainClass();
fieldDomain.AddType(esriFieldType.esriFieldTypeInteger);
fieldDomain.AddType(esriFieldType.esriFieldTypeSmallInteger);
fieldDomain.AddType(esriFieldType.esriFieldTypeSingle);
fieldDomain.AddType(esriFieldType.esriFieldTypeDouble);
fieldDomain.AddType(esriFieldType.esriFieldTypeString);
fieldDomain.AddType(esriFieldType.esriFieldTypeDate);




Then set up the parameter

// Polyline Fields
IGPParameterEdit3 polylineFieldParam = new GPParameterClass();

IGPDataType fieldDataType = new FieldTypeClass();
IGPMultiValue fieldsMultiValue = new GPMultiValueClass();
fieldsMultiValue.MemberDataType = fieldDataType;

IGPMultiValueType fieldsMultiValueType = new GPMultiValueTypeClass();
fieldsMultiValueType.MemberDataType = fieldDataType;

polylineFieldParam.DataType = fieldsMultiValueType as IGPDataType;
polylineFieldParam.Value = fieldsMultiValue as IGPValue;
polylineFieldParam.Domain = fieldDomain as IGPDomain;
polylineFieldParam.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
polylineFieldParam.DisplayName = "Fields";
polylineFieldParam.Name = "polyline_fields";
polylineFieldParam.ParameterType = esriGPParameterType.esriGPParameterTypeRequired;
polylineFieldParam.AddDependency("polyline_features");




And finally modify the dialog class used to display the parameter

// Modify the Control for displaying the fields list (the default is a combo box)
UID mdFieldListUID = new UIDClass();
mdFieldListUID.Value = "{C15EC6FA-35EF-4204-90FB-01E7B4DD6862}";
polylineFieldParam.ControlCLSID = mdFieldListUID;

parameters.Add(polylineFieldParam);




I finally found this information at the following link (see section on ControlCLSID)

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Building_a_custom_geopr...


Cheers,
Neil
0 Kudos