I have to dynamically populate a ComboBox in an add-in tool for ArcObjects using C# with the names of the fields containing text data in the feature class.

I know I have to obtain the names from the table but I'm not really sure how to go about this at all.


It's hard to tell from your code sample what you're up to.

What you're searching for is the enum esriFieldType which can be tested against each field to determine its type:

MyComboBox.items.clear(); // empty first

IFeatureLayer pFtLayer = (IFeatureLayer)gMap.get_Layer(0);
IFeatureClass pFtClass = pFtLayer.FeatureClass;
for (int Cnt = 0; Cnt < pFtClass.Fields.FieldCount; Cnt++)
    if (pFtClass.Fields.get_Field(Cnt).Type == esriFieldType.esriFieldTypeString)

Assuming your feature class comes from the first layer and your combobox is called MyComboBox... beware to set your Combobox.DropDownStyle to ComboBoxStyle.DropDownList to avoid users (accidentally) typing values in, this would mean that the value in MyComboBox.Text must be one of the items in the list or blank.

| improve this answer | |

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