tags:

views:

22

answers:

2

Hi all:

I'm having trouble hiding a SPField from the user view programmatically.

I tried the obvious way of:

SPField newField = web.Site.RotWeb.Fields.GetField("order");
string newField = list.Fields.Add(newField);
list.Fields["order"].Hidden = true; // <--- exception: read-only field
list.Update();

The exception says the field is read only so I can't modify it.

This field is added in the code and hence it'll be unghosted from the field collection. Besides from the UI, how can I make the field hidden?

Thanks.

+2  A: 

First, try setting ReadOnlyField to false (then back to true after setting Hidden).

If that does not work, check the value of CanToggleHidden. If CanToggleHidden is false, you can either:

Rich Bennema
The CanToggleHidden with reflection method worked. Thanks.
BeraCim
A: 

nevermind, I saw that you are adding the field. try getting a new instance of the field after it is created and then applying the hidden atttribute before updating the list.

brian brinley