bhavanisankarnimmala

Get Subtype code of Domain Field using arcobjects

Blog Post created by bhavanisankarnimmala on May 25, 2018

/// <summary>
        /// Get subtype code of Domain value
        /// </summary>
        /// <param name="feature"></param>
        /// <param name="fieldName"></param>
        /// <param name="fieldValue"></param>
        /// <returns></returns>
        string getSubtypeCode(IFeature feature, string fieldName, string fieldValue)
        {
            string fieldValueCode = "";
            try
            {
                if (feature.Fields.FindField(fieldName) != -1)
                {
                    IField pField = feature.Fields.get_Field(feature.Fields.FindField(fieldName));
                    IDomain pDomain = pField.Domain;
                    ICodedValueDomain2 pCodedValueDomain = pDomain as ICodedValueDomain2;
                    if (pCodedValueDomain != null)
                    {
                        for (int i = 0; i < pCodedValueDomain.CodeCount; i++)
                        {
                            if (pCodedValueDomain.get_Name(i).Equals(fieldValue))
                            {
                                fieldValueCode = pCodedValueDomain.get_Value(i).ToString();
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception : " + ex.Message);
            }
            finally
            {
                GC.Collect();
            }
            return fieldValueCode;
        }

Outcomes