Hello all,
I have a list with a dropdown field "status". I set another field f1 to be readonly and "not required" field. when adding a new list item, the initial "Status" is "proposed" and the Readonly field f1 won't show up in the "Edit form" page. So far so good.
I added 5 list items with status of "proposed". What I want is: when I edited #4 list item and changed the status to be "submitted", I would like the Readonly field f1 change to be "editable and required field" so it will show on the edit form as a required field.
*********************************************************
In the ItemUpdated Event:
public override void ItemUpdated(SPItemEventProperties properties)
{
try
{
using (SPWeb web = properties.OpenWeb())
{
SPList list = web.Lists[properties.ListId];
SPListItem item = properties.ListItem;
SPFieldCollection fields = item.Fields;
if (Convert.ToString(item["State"])!= "proposed")
{
SPField f1 = item.Fields["f1"];
f1.required = true;
f1.ReadOnlyField = false;
f1.Update();
}
}
********************************************************
The problem is : field f1 shows up on the Edit form for all the 5 items, not just #4 even though I retrieved the field f1 by properties.ListItem.Fields["f1"]. Does this mean fields can only be on List level, not list item level. what should I do if I want list item level fields ? thanks
I have a list with a dropdown field "status". I set another field f1 to be readonly and "not required" field. when adding a new list item, the initial "Status" is "proposed" and the Readonly field f1 won't show up in the "Edit form" page. So far so good.
I added 5 list items with status of "proposed". What I want is: when I edited #4 list item and changed the status to be "submitted", I would like the Readonly field f1 change to be "editable and required field" so it will show on the edit form as a required field.
*********************************************************
In the ItemUpdated Event:
public override void ItemUpdated(SPItemEventProperties properties)
{
try
{
using (SPWeb web = properties.OpenWeb())
{
SPList list = web.Lists[properties.ListId];
SPListItem item = properties.ListItem;
SPFieldCollection fields = item.Fields;
if (Convert.ToString(item["State"])!= "proposed")
{
SPField f1 = item.Fields["f1"];
f1.required = true;
f1.ReadOnlyField = false;
f1.Update();
}
}
********************************************************
The problem is : field f1 shows up on the Edit form for all the 5 items, not just #4 even though I retrieved the field f1 by properties.ListItem.Fields["f1"]. Does this mean fields can only be on List level, not list item level. what should I do if I want list item level fields ? thanks