tags:

views:

2435

answers:

5

I'm trying to hide the "Title" field in a list. This doesn't seem to work:

SPList myList;
...
SPField titleField = myList.Fields.GetField("Title");
//titleField.PushChangesToLists = true; <-- doesn't seem to make a difference
titleField.ShowInEditForm = false;
titleField.ShowInDisplayForm = false;
titleField.ShowInNewForm = false;
titleField.Update();
//myList.Update(); <-- make no difference

What am I doing wrong?

A: 

Make sure you are grabbing a new SPWeb instance.

using (SPSite site = new SPSite(webUrl))
{
    using (SPWeb web = site.OpenWeb())
    {
        try
        {
            //... Get SPList ...
        }
    }
}
Floetic
That's not it. Thanks though!
vitule
A: 

I believe visibility of fields in lists are controlled by the default view that the user "gets". Don't you want to modify the view? I know you can get the Views for a list, as well as the default view.

I'm just spit-balling here...

David Hill
my main concern is to remove the "Title" field from the New form and Edit form.
vitule
+7  A: 

Try this:

field.Hidden = true;
field.Update();
Floetic
that's embarrassing. This is exactly what I need. I still don't understand what the `ShowInEditForm` property is for but at least I can move on... Thanks (in my defense, I haven't slept all week - newborn in the house).
vitule
A: 

Are you using this in an event handler? I know the question has been answered. I would like to use this but I dont know where to put it.. ItemUpdating

Jordan Johnson
A: 

There is a price you pay when you use Hidden property.

It's been discovered that setting a column hidden will remove the ability to delete it via code.

Rosh Malai