-1

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.

closed as off-topic by PolyGeo Jan 22 at 0:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

3

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)
    {
        MyComboBox.items.add(pFtClass.Fields.get_Field(Cnt).Name);
    }
}

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.

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