I am creating a view from code behind. The view contains Title column for which I would like to be a link to open the list item and have a drop-down menu.
I know that this is done by setting <FieldRef Name='Title' ListItemMenu='TRUE' />, but how can I achieve the same thing from code behind?
Here is the code for creating a view:
private SPView CreateView(SPList list, string title, string[] columnDisplayNames)
{
StringCollection columns;
string columnInternalName;
SPViewCollection views;
SPView view;
columns = new StringCollection();
foreach (string columnDisplayName in columnDisplayNames)
{
columnInternalName = this.GetListColumnInternalName(list, columnDisplayName);
columns.Add(columnInternalName);
}
views = list.Views;
view = views.Add(title, columns, string.Empty, 30, true, true);
view.Update();
for (int i = views.Count - 2; i >= 0; i--)
{
views.Delete(views[i].ID);
}
return view;
}
Note:
The accepted answer in this question is false, as the Title field that has ListItemMenu is LinkTitle (internal name) and using that column throws an exception.