protected void AddItemsToColumnSelectMenu(ToolStripItemCollection items)
{
// Sort columns by display order
List<OLVColumn> columns = new List<OLVColumn>(this.AllColumns);
columns.Sort(delegate(OLVColumn x, OLVColumn y) { return (x.LastDisplayIndex - y.LastDisplayIndex); });
// Build menu from sorted columns
foreach (OLVColumn col in columns) {
ToolStripMenuItem mi = new ToolStripMenuItem(col.Text);
mi.Checked = col.IsVisible;
mi.Tag = col;
// The 'Index' property returns -1 when the column is not visible, so if the
// column isn't visible we have to enable the item. Also the first column can't be turned off
mi.Enabled = !col.IsVisible || col.CanBeHidden;
items.Add(mi);
}
}