Custom Field for lists - property value not restored
Hi,
We have been developing our own custom fields and controls for SharePoint Lists. They all work fine. The problem is, that we now have the need to specify some settings for our custom controls. We made this possible by implementing a property, that the user may set when creating a new list column with the given field type. This also works great. The problem occures when the user wants to modify the column. The value set in the property is not restored (see screenshot: http://img222.imageshack.us/img222/6683/valuenotrestored.png).
The following is a simplified version of my field definition file (fldtypes_xyz.xml):
<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">CompanySelectEnum</Field>
<Field Name="ParentType">Text</Field>
<Field Name="TypeDisplayName">$Resources:Company,SPFields_Name_SelectEnum</Field>
<Field Name="TypeShortDescription">$Resources:Company,SPFields_Description_SelectEnum</Field>
<Field Name="FieldTypeClass">CompanySPControls.SPSelectEnumField, CompanySPControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9109eca8fce563d2</Field>
<RenderPattern Name="DisplayPattern">
<Column HTMLEncode="TRUE" />
</RenderPattern>
<PropertySchema>
<Fields>
<Field Name="SelectEnum" DisplayName="Select Enum" Required="TRUE" DisplaySize="50" MaxLength="200" Type="Text" />
</Fields>
</PropertySchema>
</FieldType>
</FieldTypes>As you can see, the property is defined in the PropertySchema section. In the code behind the property is defined like this:
public string SelectEnum
{
get { return (string)this.GetCustomProperty("SelectEnum"); }
set { this.SetCustomProperty("SelectEnum", value); }
}The property is indeed both saved and available. The only problem is, that the value is not displayed in the property field when editing the column based on the field.
Any help on this topic would be greatly appriciated.
- Thanks in advance
Best regards
Jimmy Thomsen
Answers
- Hi Jimmy,
There are a few articles out there that suggest that the default implementation of GetCustomProperty & SetCustomProperty are a bit buggy. Personally I haven't had any problems with them but it may be worthwhile trying one of the alternative implementations to see if that helps.
Have a look at this post, it explains the problem and provides some code to fix it: http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/fb1cb936-3abb-48c2-8d19-49007688dc34/
Hope this helps!
Ch. - My Blog- Marked As Answer byAaron Han - MSFTModeratorWednesday, November 11, 2009 2:11 AM
Hi, Jimmy
Yes, as Charlie’s suggestion and link, custom field type values are not available via a <Property Select='myValue'/>.
I would also recommend override OnAdded() and OnUpdated() methods with GetCustomProperty and base.SchemaXml
Here is a Todd’s good article for this:
http://blogs.msdn.com/toddca/archive/2009/01/23/customizing-the-rendering-of-a-custom-spfield.aspx
Hope this can be helpful.
Best Regards,
-Aaron
- Marked As Answer byAaron Han - MSFTModeratorWednesday, November 11, 2009 2:11 AM
All Replies
- Hi Jimmy,
There are a few articles out there that suggest that the default implementation of GetCustomProperty & SetCustomProperty are a bit buggy. Personally I haven't had any problems with them but it may be worthwhile trying one of the alternative implementations to see if that helps.
Have a look at this post, it explains the problem and provides some code to fix it: http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/fb1cb936-3abb-48c2-8d19-49007688dc34/
Hope this helps!
Ch. - My Blog- Marked As Answer byAaron Han - MSFTModeratorWednesday, November 11, 2009 2:11 AM
Hi, Jimmy
Yes, as Charlie’s suggestion and link, custom field type values are not available via a <Property Select='myValue'/>.
I would also recommend override OnAdded() and OnUpdated() methods with GetCustomProperty and base.SchemaXml
Here is a Todd’s good article for this:
http://blogs.msdn.com/toddca/archive/2009/01/23/customizing-the-rendering-of-a-custom-spfield.aspx
Hope this can be helpful.
Best Regards,
-Aaron
- Marked As Answer byAaron Han - MSFTModeratorWednesday, November 11, 2009 2:11 AM

