Just thought I would share a tip that I found on the usenet group: microsoft.public.sharepoint.windowsservices.development
and in particular a post made by Colin Byrne colinb@>flexnetconsult.co.uk
I am summarizing the tip below in brief with thanks to Colin for the very useful information:
nbsp;
-------------------
Question: How does one create a list field that is hidden from users, but can be accessed for use in WorkFlows, etc?
Answer:Apparently, the hidden property of a list field (SPField) cannot be changed because it is blocked by the internal property CanToggleHidden being false. You can't adjust this though the public object model.
There are two work arounds, via code.
1. Add the field as XML
list.Fields.AddFieldAsXml("<Field DisplayName=\"NewField5\"
Type=\"Boolean\" Required=\"FALSE\" Name=\"NewField5\"
CanToggleHidden=\"TRUE\" Hidden=\"TRUE\"/>");
2. Set the internal CanToggleHidden property via reflection
string id=list.Fields.Add("NewField5",SPFieldType.Boolean,false);
SPField spfield=(SPField)list.Fields.GetField(id);
Type type = spfield.GetType();
MethodInfo mi= type.GetMethod("SetFieldBoolValue",
BindingFlags.NonPublic | BindingFlags.Instance);
mi.Invoke(spfield,new object[]{"CanToggleHidden", true});
spfield.Hidden=true;
spfield.Update();