Hi All,
I am new to this ArcObjects SDK C#.
I want to get domain values and subtypes values of a field in the geodatabase using ArcObjects SDK C#.
Can anyone help me in this.
Solved! Go to Solution.
Hi,
Look here:
Or another way is to get IDomain from IField:
IDomain pDomain = pField.Domain;
if(pDomain != null) {
esriDomainType enDType = pDomain.Type;
if(enDType == esriDomainType.esriDTCodedValue) {
ICodedValueDomain pCVDom = pDomain as ICodedValueDomain;
int nCount = pCVDom.CodeCount;
for (int j = 0; j < nCount; j++) {
object v1 = pCVDom.Value[j];
string strDName = pCVDom.Name[j];
}
}
}
Hi,
Look here:
Or another way is to get IDomain from IField:
IDomain pDomain = pField.Domain;
if(pDomain != null) {
esriDomainType enDType = pDomain.Type;
if(enDType == esriDomainType.esriDTCodedValue) {
ICodedValueDomain pCVDom = pDomain as ICodedValueDomain;
int nCount = pCVDom.CodeCount;
for (int j = 0; j < nCount; j++) {
object v1 = pCVDom.Value[j];
string strDName = pCVDom.Name[j];
}
}
}
Hi,
Thanks for your reply.
Can you please tell me how to represent the pField which is in line number 1.
IFeatureClass pFc = (IFeatureClass)pDs;
for (int i = 0; i < pFc.Fields.FieldCount; i++)
{
IField f = pFc.Fields.get_Field(i);
string name = f.Name;
Columnlist.Add(name);
IDomain pDomain = f.Domain;
if (pDomain != null)
{
esriDomainType enDType = pDomain.Type;
if (enDType == esriDomainType.esriDTCodedValue)
{
ICodedValueDomain pCVDom = pDomain as ICodedValueDomain;
int nCount = pCVDom.CodeCount;
for (int j = 0; j < nCount; j++)
{
object v1 = pCVDom.Value[j];
string strDName = pCVDom.Name[j];
MessageBox.Show(strDName);
}
}
}
else
{
MessageBox.Show("No coded value domain");
}
//collect these...
// MessageBox.Show(name);
}
When I'm trying above code I'm getting p.domain as NULL.
But the field has domain.
Can you please suggest solution for this? It will be more helpful
I don't know your workflow. You can get it by many different ways. By index or name from IFields type object which you can get from ITable type object (in samples pTable variable)
IFields pFields = pTable.Fields;
int iFieldsCount = pFields.FieldCount;
for (int i = 0; i < iFieldsCount; i++)
{
IField pField = pFields.get_Field(i);
// code with domain
}
or
IFields pFields = pTable.Fields;
int fieldIndex = pTable.FindField(fieldName);
IField pField = pFields.get_Field(fieldIndex);
Hi,
Thanks for your reply.
It helps!