SharePoint 2010: Showing the Context menu on any field in a List View when defining lists

I am working on a project that requires me to show the context menu on columns other than the default ‘Title” field that normally shows up (at least when creating a list based on the “Item” template).   While doing research I came across two different ways to do this when using XML to define the lists.

The first just involves renaming the “Title” field to something else.  I was taking this approach as I was playing with Visual Studio 2012RC’s new wizards for creating lists and content types (what are great!!!).   While the wizard allows you to change “Title” to whatever you want it never changed the text that shows up in the view header, only when add/editing the item.  Close but no cigar.  Looking at the code that gets generated I saw:





This sets the field when adding/editing a new entry but doesn’t change the header.   After much head banging and powershell scripting I figured out that I needed to add:

Field ID={fa564e0f-0c70-4ab9-b863-0177e6ddd247} Type=Text Name=Title DisplayName=Name Required=TRUE SourceID= StaticName=Title MaxLength=255/>





Field ID={82642ec8-ef9b-478f-acf9-31f7d45fbc31} Type=Text Name=LinkTitle DisplayName=Name />

as well. This is the field that is typically named “Title (linked to item with edit menu)”  Note that the “DisplayName” in both lines have been changed to what I want to actually show.  So now the header will be “Name” and the if I create a new view I will see “Name (linked to item with edit menu)”.

That worked fine for lists that use the existing “Title” field but what about lists that don’t have it or what if I needed to change the field that is used to display the menu depending on the view (which was actually the case)  For this I turned to code….sort of.  I was looking through the object model and saw that I can use “SPField.ListItemMenu” to set the field that I wanted to use.  Taking a chance I added “ListItemMenu=’True’ ” to the field I wanted to use and it worked!

So there you go.  Two different ways to change where the context menu shows!

Leave a Reply