Change the layer properties through code?

1656
2
03-10-2010 03:34 PM
Highlighted
Regular Contributor
Hello,

Is it possible to change the layer properties through code? I would like to be able to change the visibility and read only states of a few fields in several of my feature classes. These fields are used to support IRelationshipClass assignments and should not be changed by the user during an edit session. Currently these fields are exposed to the end user and can potentially be altered creating issues for the relationships. The user can manually alter these fields on their own but I have not found any ArcObjects that expose a method for altering the values through code. I have attached a screen shot of the fields I'm specifically talking about. Please be clear I am not looking for a way to make the entire layer read only or not visible, just specific fields in the layer itself.

G
Reply
0 Kudos
2 Replies
Highlighted
Esri Regular Contributor
Hi Grieck,
The readonly property can be set through the IFieldInfo3.ReadOnly property.
This setting only applies to the clients that choose to implement it such as the editor attribute window.
Reply
0 Kudos
Highlighted
Regular Contributor
This is interesting. I had first opened an incident with ESRI support and was told the functionality I was looking for did not exist and I was not able to alter the visibility or read only state of the layer properties. Then along comes Sean who points me to IFieldInfo3. I was able to get this to work just like I wanted it to.

I have wired IEditEvents5.OnCurrentTemplateChanged Event where I trap for the user switching between Edit Templates. When they do I loop through and set the fields visibility and read only states as needed. Granted there is probably a better event to trap this on but this event was already wired and had a hook to ILayer.


    public void OnCurrentTemplateChanged(IEditTemplate editTemplate)
    {
      IFieldInfo3 Info3 = new FieldInfoClass();
      IFeatureLayer2 featlayer2 = editTemplate.Layer as IFeatureLayer2;
      ILayerFields layerflds = editTemplate.Layer as ILayerFields;
      IFeatureClass featclass = featlayer2.FeatureClass;
      IField2 fld2 = featclass.Fields as IField2;
      switch (editTemplate.Name.ToLower())
      {
        case "your layer name here":
          for (int g = 0; g < featclass.Fields.FieldCount; g++)
          {
            fld2 = featclass.Fields.get_Field(g) as IField2;
            Info3 = layerflds.get_FieldInfo(g) as IFieldInfo3;
            switch (fld2.Name.ToLower())
            {
              case "field1":
              case "field2":
              case "field3":
              case "field4":
                Info3.Readonly = true;
                break;
              case "field5":
              case "field6":
                Info3.Visible = false;
                break;
            }
          }
          break;
      }
    }


THANK YOU SEAN!

IFieldInfo3
http://help.esri.com/en/sdk/9.4/ArcObjects_NET/ComponentHelp/index.htm#/d/00250000035Q000000/

OnCurrentTemplateChangeEvent
http://help.esri.com/en/sdk/9.4/Arcobjects_net/ComponentHelp/index.htm#//0020000000N8000000
Reply
0 Kudos