Wednesday, October 21, 2009

SharePoint Custom Lists and the Item Context Menu

When you need to build a custom list in SharePoint, there are a few things you need to know, apart from the procedure of putting some files of code together.

The first important thing is that the Title property of a list item can never be removed - it can be hidden, made optional, but not deleted.
The second thing is that the Title field is the only field that has the context menu - this menu cannot be attached to any other field.
And the third thing is that you can use the Title field to your advantage - change its display name and some other properties that you need, and create a field that benefits of the context menu and that also fits into your list. The thing to remember is that the NAME of the field will remain “Title”, only the Displayed Name has been made custom.

To benefit of the custom menu, there are 3 things you should make sure to add in your schema.xml file:
1. the Title field declaration ( with its original ID and the Display Name customized - or not ):

<Field ID=”{fa564e0f-0c70-4ab9-b863-0177e6ddd247}” Name=”Title” DisplayName=”My Field” Sealed=”TRUE” Type=”Text” />

2. the LinkTitle and LinkTitleNoMenu elements (which are the declarations of the contextual menu and link item respectively) with the Display Name changed accordingly:

<Field Name=”LinkTitle” ID=”{82642ec8-ef9b-478f-acf9-31f7d45fbc31}” DisplayName=”My Field” SourceID=”http://schemas.microsoft.com/sharepoint/v3″/>
<Field Name=”LinkTitleNoMenu” ID=”{bc91a437-52e7-49e1-8c4e-4698904b2b6d}” DisplayName=”My Field” SourceID=”http://schemas.microsoft.com/sharepoint/v3” />

3. and last but no least, the thing that does the trick - add the LinkTitle element to the Views in the schema.xml file, leaving the Title field out:

<ViewFields>
<FieldRef Name=”LinkTitle” />
… other fields, NOT Title

</ViewFields>

You will now benefit of the contex menu on your custom Title field.

Productive coding!

Posted by Madalina at 22:57:27
Comments

Leave a Reply