Select to view content in your preferred language

Getting domain and subtypes values in Arcobjects C#

1415
4
Jump to solution
11-24-2022 12:04 AM
ShanmugapriyaL1
New Contributor II

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.

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

Look here:

https://gis.stackexchange.com/questions/365039/arcobjects-vb-net-looping-through-domains-of-a-subtyp... 

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];
		}
	}
}

 

View solution in original post

0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Look here:

https://gis.stackexchange.com/questions/365039/arcobjects-vb-net-looping-through-domains-of-a-subtyp... 

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];
		}
	}
}

 

0 Kudos
ShanmugapriyaL1
New Contributor II

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

0 Kudos
GKmieliauskas
Esri Regular Contributor

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);
0 Kudos
ShanmugapriyaL1
New Contributor II

Hi,

Thanks for your reply.

It helps!

0 Kudos