private static void FillMenuItems(List<MySQL.Base.MenuItem> itemsBE, ToolStripItemCollection itemsFE) { foreach (MySQL.Base.MenuItem itemBE in itemsBE) { switch (itemBE.get_type()) { case MySQL.Base.MenuItemType.MenuSeparator: { itemsFE.Add(new ToolStripSeparator()); } break; default: { ToolStripMenuItem itemFE = new ToolStripMenuItem(); itemFE.Tag = itemBE.get_name(); itemFE.Text = itemBE.get_caption(); itemFE.Enabled = itemBE.get_enabled(); if (MySQL.Base.MenuItemType.MenuCascade == itemBE.get_type()) { FillMenuItems(itemBE.get_subitems(), itemFE.DropDownItems); } else { itemFE.Click += new EventHandler(OnMenuItemClick); } itemsFE.Add(itemFE); } break; } } }
public static void BuildMenu(ToolStripItemCollection items, IEnumerable<IEditorScript> scripts, Action<IEditorScript> callback) { foreach (var script in scripts) { if (script.Name.StartsWith("----")) { items.Add(new ToolStripSeparator()); } else if (script.Children.Any()) { var item = new ToolStripMenuItem(script.Name); BuildMenu(item.DropDownItems, script.Children, callback); items.Add(item); } else { items.Add(new ToolStripMenuItem(script.Name, null, (s, ev) => { var query = script.Script; // Trigger execution if (!string.IsNullOrEmpty(query)) { callback(script); } })); } } }
public static void BuildMenu(ToolStripItemCollection items, IEnumerable<IEditorScript> scripts, Func<IEditorScript, Task> callback) { foreach (var script in scripts) { if (script.Name.StartsWith("----")) { items.Add(new ToolStripSeparator()); } else if (script.Children.Any()) { var item = new ToolStripMenuItem(script.Name); BuildMenu(item.DropDownItems, script.Children, callback); items.Add(item); } else { items.Add(new ToolStripMenuItem(script.Name, null, async (s, ev) => { var text = await script.GetScript(); // Trigger execution if (!string.IsNullOrEmpty(text)) { await callback(script); } })); } } }
private static void PopulateItems(ToolStripItemCollection items, IEnumerable<CommandMenuGroup> groups, CommandRegistry registry) { List<CommandMenuGroup> groupList = groups as List<CommandMenuGroup>; if (groupList == null) groupList = new List<CommandMenuGroup>(groups); foreach (CommandMenuGroup group in groupList) { if (group != groupList[0]) items.Add(new ToolStripSeparator()); foreach (CommandMenuEntry entry in group) { if (entry.SubMenu != null) items.Add(BuildToolStripMenu(entry.SubMenu, registry)); else { CommandRecord record = registry.Lookup(entry.Key); if (record != null) { ToolStripMenuItem menuItem = new ToolStripMenuItem() { Tag = entry.Key, Text = record.DisplayName, Image = record.Image, ShortcutKeys = record.Shortcut, ShortcutKeyDisplayString = record.ShortcutDisplay, ToolTipText = record.Description, }; items.Add(menuItem); } } } } }
/// <summary> /// Fills items to the specified tool strip item collection /// </summary> public static void FillToolItems(ToolStripItemCollection items, XmlNode node) { switch (node.Name) { case "separator": items.Add(GetSeparator(node)); break; case "button": items.Add(GetButtonItem(node)); break; } }
/// <summary> /// Add the contents of this MergableMenu to a CommandBarMenu /// </summary> /// <param name="menu"></param> public void Apply(ToolStripItemCollection items) { int lastGroup = -1; foreach (MergableItem item in List) { if (item.Group != lastGroup && lastGroup > -1) items.Add(new ToolStripSeparator()); items.Add(item.Apply()); lastGroup = item.Group; } }
private static void CreateButton(ToolStripItemCollection items, string title, EventHandler handler, Workitem item) { var button = new ToolStripMenuItem(title, null, handler); items.Add(button); button.Tag = item; }
public static void Sort(ToolStripItemCollection collection, IComparer comparer) { ArrayList items = new ArrayList(collection); items.Sort(comparer); collection.Clear(); foreach (object itm in items) collection.Add(itm as ToolStripItem); }
ToolStripMenuItem GetNamedChild(ToolStripItemCollection container, string name) { foreach (ToolStripMenuItem item in container) if (name == item.Text) return item as ToolStripMenuItem; ToolStripMenuItem newItem = new ToolStripMenuItem(name); container.Add(newItem); return newItem; }
/// <summary> /// Add template to a specific list /// </summary> /// <param name="collection">List, where to add template</param> /// <param name="template">Template to add</param> /// <param name="onClick">Click handlers</param> public static void InsertTemplate(ToolStripItemCollection collection, MoneyDataSet.TransactionTemplatesRow template, EventHandler onClick) { Image image = null; if (template.ID.Equals(MoneyDataSet.IDs.TransactionTemplates.Transfer)) { image = Properties.Resources.table_relationship; } ToolStripMenuItem tsmiFromTemplate = new ToolStripMenuItem(template.Title, image, onClick); tsmiFromTemplate.Tag = template; tsmiFromTemplate.ToolTipText = template.Message; collection.Add(tsmiFromTemplate); }
static void AddItemsToMenu(ToolStripItemCollection collection, IEnumerable<MenuItemDescriptor> descriptors) { foreach (MenuItemDescriptor descriptor in descriptors) { object item = CreateMenuItemFromDescriptor(descriptor); if (item is ToolStripItem) { collection.Add((ToolStripItem)item); if (item is IStatusUpdate) ((IStatusUpdate)item).UpdateStatus(); } else { IMenuItemBuilder submenuBuilder = (IMenuItemBuilder)item; collection.AddRange(submenuBuilder.BuildItems(descriptor.Codon, descriptor.Parameter).Cast<ToolStripItem>().ToArray()); } } }
/// <summary> /// Fills items to the specified tool strip item collection /// </summary> public static void FillMenuItems(ToolStripItemCollection items, XmlNode node) { switch (node.Name) { case "menu" : String name = XmlHelper.GetAttribute(node, "name"); if (name == "SyntaxMenu") node.InnerXml = GetSyntaxMenuXml(); items.Add(GetMenu(node)); break; case "separator" : items.Add(GetSeparator(node)); break; case "button" : ToolStripMenuItem menu = GetMenuItem(node); items.Add(menu); // Add menu first to get the id correct String id = GetMenuItemId(menu); if (id.IndexOf('.') > -1) { Globals.MainForm.RegisterShortcutItem(GetMenuItemId(menu), menu); } break; } }
public static void Update(System.Windows.Forms.ToolStripItemCollection toolStripItemCollection, ToolStripItemCodonCollection codonCollection) { if (codonCollection == null || toolStripItemCollection == null) { Debug.Assert(false, "ToolStripItemCollection 或 CodonCollection为null"); return; } toolStripItemCollection.Clear(); foreach (IToolStripItemCodon codon in codonCollection) { toolStripItemCollection.Add((ToolStripItem)codon.View); } }
static void AddItemsToMenu(ToolStripItemCollection collection, List<MenuItemDescriptor> descriptors) { foreach (MenuItemDescriptor descriptor in descriptors) { object item = CreateMenuItemFromDescriptor(descriptor); if (item is ToolStripItem) { collection.Add((ToolStripItem)item); if (item is IStatusUpdate) ((IStatusUpdate)item).UpdateStatus(); } else { ISubmenuBuilder submenuBuilder = (ISubmenuBuilder)item; collection.AddRange(submenuBuilder.BuildSubmenu(descriptor.Codon, descriptor.Caller)); } } }
public static void AddItemsToMenu(ToolStripItemCollection collection, object owner, string addInTreePath) { ArrayList buildItems = AddInTree.GetTreeNode(addInTreePath).BuildChildItems(owner); foreach (object item in buildItems) { if (item is ToolStripItem) { collection.Add((ToolStripItem)item); if (item is IStatusUpdate) ((IStatusUpdate)item).UpdateStatus(); } else { ISubmenuBuilder submenuBuilder = (ISubmenuBuilder)item; collection.AddRange(submenuBuilder.BuildSubmenu(null, owner)); } } }
private void addSaveSlots(ToolStripItemCollection items) { //test(mnuSaveSlots.DropDownItems); ToolStripMenuItem mnuAll = new ToolStripMenuItem(); // // mnuAll // mnuAll.Name = "mnuAll"; mnuAll.Size = new System.Drawing.Size(152, 22); mnuAll.Text = "All"; mnuAll.Click += new EventHandler(this.mnuAll_Click); items.Add(mnuAll); for (int i = 1; i <= 20; i++) { ToolStripMenuItem mnuSlot; mnuSlot = new ToolStripMenuItem(); mnuSlot.Name = "mnuSlot" + i; mnuSlot.Size = new System.Drawing.Size(152, 22); mnuSlot.Text = "Slot " + i; mnuSlot.Click += new System.EventHandler(this.mnuSlot_Click); items.Add(mnuSlot); } }
public static void AddItemsToMenu(ToolStripItemCollection collection, object owner, string addInTreePath) { ArrayList list = AddInTree.GetTreeNode(addInTreePath).BuildChildItems(owner); foreach (object obj2 in list) { if (obj2 is ToolStripItem) { collection.Add((ToolStripItem) obj2); if (obj2 is IStatusUpdate) { ((IStatusUpdate) obj2).UpdateStatus(); } } else { ISubmenuBuilder builder = (ISubmenuBuilder) obj2; collection.AddRange(builder.BuildSubmenu(null, owner)); } } }
private void CreateNewDocMenuItems(ToolStripItemCollection col) { col.Clear(); ToolStripMenuItem newFolderItem = new ToolStripMenuItem("Folder", kwm.KwmAppControls.Properties.Resources.newfolder_16x16, HandleListviewCreateDirectoryMenu, "CreateDir"); newFolderItem.ImageTransparentColor = Color.Magenta; col.Add(newFolderItem); col.Add(new ToolStripSeparator()); List<NewDocument> newDocs = Misc.GetNewDocs(false); foreach (NewDocument doc in newDocs) { ToolStripMenuItem newItm = new ToolStripMenuItem(doc.DisplayName, doc.TypeIcon.ToBitmap(), HandleNewDocClicked, null); newItm.Tag = doc; col.Add(newItm); } }
public ClipboardApplication() { clipboardNotifier.ClipboardChanged += HandleClipboard; if (settings.autoCleanInterval > 0) { cleanupTimer.Interval = settings.autoCleanInterval * 1000; } cleanupTimer.Tick += HandleCleanUpClicked; notifyIcon.DoubleClick += HandleCleanUpClicked; NumericUpDown intervalItemBox = new NumericUpDown { Minimum = 0, Maximum = int.MaxValue, Value = settings.autoCleanInterval, }; intervalItemBox.ValueChanged += HandleIntervalChange; NumericUpDown historyCountBox = new NumericUpDown { Minimum = 0, Maximum = int.MaxValue, Value = settings.maxHistoryObjects, }; historyCountBox.ValueChanged += HandleHistoryCountChange; TSItems children = notifyIcon.ContextMenuStrip.Items; children.AddRange(new TSItem[] { new TSLabel(string.Format(Language.Caption, Application.ProductName, Application.ProductVersion)), new TSSeparator(), new TSLabel(Language.ExistsDataCaption), dataDisplay, imageDataDisplay, new TSMenuItem(Language.ClearNow, null, HandleCleanUpClicked), new TSMenuItem(Language.Pin, null, HandlePinClick), new TSSeparator(), }); pinned = new HistoryMenu(children, Language.PinnedMenu); children.Add(new TSSeparator()); history = new HistoryMenu(children, Language.HistoryMenu) { removeOnUse = true }; children.AddRange(new TSItem[] { new TSSeparator(), new TSLabel(Language.AutoCleanAt), new ToolStripControlHost(intervalItemBox), new TSLabel(Language.EnableHistory), new ToolStripControlHost(historyCountBox), new TSMenuItem(Language.NotifyChanges, null, HandleNotifyToggle) { Checked = settings.notifyEnabled, }, new TSMenuItem(Language.RunAtStartup, null, RunAtStartupClick) { Checked = RunAtStartup }, new TSSeparator(), new TSMenuItem(Language.Exit, null, HandleExitClick), }); HandleClipboard(false, Clipboard.GetDataObject()); Application.ApplicationExit += HandleApplicationExit; }
private void MergeMenu(ToolStripItemCollection source, ToolStripItemCollection dest) { while(source.Count > 0) { ToolStripMenuItem item = (ToolStripMenuItem) source[0]; if(item.MergeAction == MergeAction.Insert) { for(int index = 0; index < dest.Count; ++index) { if(dest[index].MergeIndex > item.MergeIndex) { dest.Insert(index, item); break; } } } else if (item.MergeAction == MergeAction.Append) { dest.Add(item); } else if (item.MergeAction == MergeAction.MatchOnly) { ToolStripMenuItem match = null; foreach(ToolStripMenuItem destitem in dest) { if(destitem.Text == item.Text) { match = destitem; break; } } if(match == null) throw new ApplicationException("Can't merge with nonexistent menu '" + item.Text + "'"); MergeMenu(item.DropDownItems, match.DropDownItems); source.Remove(item); } else { throw new ApplicationException("Unsupported menu merge action"); } } }
/// <summary> /// Builds a menu from the specified action model nodes. /// </summary> /// <param name="parentItemCollection"></param> /// <param name="nodes"></param> public static void BuildMenu(ToolStripItemCollection parentItemCollection, IEnumerable<ActionModelNode> nodes) { List<ActionModelNode> nodeList = CombineAdjacentSeparators(new List<ActionModelNode>(nodes)); foreach (ActionModelNode node in nodeList) { ToolStripItem toolstripItem; if (node is ActionNode) { // this is a leaf node (terminal menu item) ActionNode actionNode = (ActionNode) node; IAction action = actionNode.Action; IActionView view = CreateActionView(ToolStripKind.Menu, action, IconSize.Medium); toolstripItem = (ToolStripItem)view.GuiElement; toolstripItem.Tag = new ItemTag(node, view); parentItemCollection.Add(toolstripItem); // Determine whether we should check the parent menu items too IClickAction clickAction = actionNode.Action as IClickAction; if (clickAction != null && clickAction.CheckParents && clickAction.Checked) CheckParentItems(toolstripItem); } else if (node is SeparatorNode) { toolstripItem = new ToolStripSeparator(); toolstripItem.Tag = new ItemTag(node, null); parentItemCollection.Add(toolstripItem); } else { // this menu item has a sub menu toolstripItem = new ToolStripMenuItem(node.PathSegment.LocalizedText); toolstripItem.Tag = new ItemTag(node, null); parentItemCollection.Add(toolstripItem); BuildMenu(((ToolStripMenuItem)toolstripItem).DropDownItems, node.ChildNodes); } // When you get Visible, it refers to whether the object is really visible, as opposed to whether it _can_ be visible. // When you _set_ Visible, it affects whether it _can_ be visible. // For example, an item is really invisible but _can_ be visible before it is actually drawn. // This is why we use the Available property, which give us the information when we are interested in "_Could_ this be Visible?" ToolStripMenuItem parent = toolstripItem.OwnerItem as ToolStripMenuItem; if (parent != null) { SetParentAvailability(parent); toolstripItem.AvailableChanged += delegate { SetParentAvailability(parent); }; } } }
/// <summary> /// Builds a toolbar from the specified action model nodes, using the specified style and size. /// </summary> /// <param name="parentItemCollection"></param> /// <param name="nodes"></param> /// <param name="builderStyle"></param> /// <param name="iconSize"></param> public static void BuildToolbar(ToolStripItemCollection parentItemCollection, IEnumerable<ActionModelNode> nodes, ToolStripBuilderStyle builderStyle, IconSize iconSize) { List<ActionModelNode> nodeList = CombineAdjacentSeparators(new List<ActionModelNode>(nodes)); // reverse nodes if alignment is right if (builderStyle.ToolStripAlignment == ToolStripItemAlignment.Right) nodeList.Reverse(); foreach (ActionModelNode node in nodeList) { if (node is ActionNode) { IAction action = ((ActionNode)node).Action; IActionView view = CreateActionView(ToolStripKind.Toolbar, action, iconSize); ToolStripItem button = (ToolStripItem)view.GuiElement; button.Tag = new ItemTag(node, view); // By default, only display the image on the button button.DisplayStyle = builderStyle.ToolStripItemDisplayStyle; button.Alignment = builderStyle.ToolStripAlignment; button.TextImageRelation = builderStyle.TextImageRelation; parentItemCollection.Add(button); } else if(node is SeparatorNode) { ToolStripSeparator separator = new ToolStripSeparator(); separator.Tag = new ItemTag(node, null); parentItemCollection.Add(separator); } else { BuildToolbar(parentItemCollection, node.ChildNodes, builderStyle, iconSize); } } }
private static void AddToolStripItems(ToolStripItemCollection items, IEnumerable<ToolStripMenuItem> toolStripItems) { foreach (ToolStripMenuItem toolStripItem in toolStripItems) { items.Add(toolStripItem); } }
public static void CreatePacketLogCopyItems(ToolStripItemCollection items, Func<IEnumerable<LogPacket>> createPackets) { ToolStripMenuItem packetLog = new ToolStripMenuItem(Properties.Resources.GuiUtils_CopyToPacketLog); ToolStripMenuItem testDoc = new ToolStripMenuItem(Properties.Resources.GuiUtils_CopyToTestDocument); ToolStripMenuItem diffDoc = new ToolStripMenuItem(Properties.Resources.GuiUtils_CopyToDiffDocument); ToolStripMenuItem item = new ToolStripMenuItem(Properties.Resources.GuiUtils_NewDocument); item.Click += (s, e) => newLog_Click(s, createPackets); packetLog.DropDownItems.Add(item); item = new ToolStripMenuItem(Properties.Resources.GuiUtils_NewDocument); diffDoc.DropDownItems.Add(item); ToolStripMenuItem subItem = new ToolStripMenuItem(Properties.Resources.GuiUtils_LeftDiffDocument); subItem.Click += (s, e) => newDiffLog_Click(s, createPackets, true); item.DropDownItems.Add(subItem); subItem = new ToolStripMenuItem(Properties.Resources.GuiUtils_RightDiffDocument); subItem.Click += (s, e) => newDiffLog_Click(s, createPackets, false); item.DropDownItems.Add(subItem); foreach (IDocumentObject doc in CANAPEProject.CurrentProject.Documents) { if ((doc is TestDocument) || (doc is PacketLogDocument)) { item = new ToolStripMenuItem(doc.Name); item.Click += (s, e) => addToExisting_Click(s, createPackets); item.Tag = doc; if (doc is PacketLogDocument) { packetLog.DropDownItems.Add(item); } else { testDoc.DropDownItems.Add(item); } } else if (doc is PacketLogDiffDocument) { item = new ToolStripMenuItem(doc.Name); diffDoc.DropDownItems.Add(item); subItem = new ToolStripMenuItem(Properties.Resources.GuiUtils_LeftDiffDocument); subItem.Click += (s, e) => addToExistingDiffLog_Click(s, createPackets, true); subItem.Tag = doc; item.DropDownItems.Add(subItem); subItem = new ToolStripMenuItem(Properties.Resources.GuiUtils_RightDiffDocument); subItem.Click += (s, e) => addToExistingDiffLog_Click(s, createPackets, false); subItem.Tag = doc; item.DropDownItems.Add(subItem); } } items.Add(packetLog); items.Add(diffDoc); if (testDoc.DropDownItems.Count > 0) { items.Add(testDoc); } }
//helper function to find or add a menu item private ToolStripMenuItem FindOrAddMenuItem(ToolStripItemCollection list, string name) { int iCount = list.Count; for (int i = 0; i < iCount; i++) { ToolStripMenuItem item = (ToolStripMenuItem)list[i]; if (string.Compare(item.Text, name, true) == 0) return item; } //not found, so create menu item ToolStripMenuItem itemToAdd = new ToolStripMenuItem(name); list.Add(itemToAdd); return itemToAdd; }
/// <summary> /// 添加子菜单 /// </summary> /// <param name="text">要显示的文字,如果为 - 则显示为分割线</param> /// <param name="cms">要添加到的子菜单集合</param> /// <param name="callback">点击时触发的事件</param> /// <returns>生成的子菜单,如果为分隔条则返回null</returns> ToolStripMenuItem AddContextMenu(string text, ToolStripItemCollection cms, EventHandler callback) { if (text == "-") { ToolStripSeparator tsp = new ToolStripSeparator(); cms.Add(tsp); return null; } else if (!string.IsNullOrEmpty(text)) { ToolStripMenuItem tsmi = new ToolStripMenuItem(text); tsmi.Tag = text + "TAG"; if (callback != null) tsmi.Click += callback; cms.Add(tsmi); return tsmi; } return null; }
private static ToolStripMenuItem FindOrCreateAlgoMenuItem(ToolStripItemCollection parent, CoinAlgorithm algorithm) { ToolStripMenuItem algoItem = null; foreach (ToolStripMenuItem item in parent) { if (item.Text.Equals(algorithm.ToString())) { algoItem = item; break; } } if (algoItem == null) { algoItem = new ToolStripMenuItem() { Text = algorithm.ToString() }; parent.Add(algoItem); } return algoItem; }
private void FillRemotesToolStrip(ToolStripItemCollection strip, bool includeLocalhost) { ToolStripItem[] items = new ToolStripItem[m_Core.Config.RemoteHosts.Count]; int idx = 0; for (int i = 0; i < m_Core.Config.RemoteHosts.Count; i++) { RemoteHost host = m_Core.Config.RemoteHosts[i]; // add localhost at the end if (host.Hostname == "localhost") continue; ToolStripItem item = new ToolStripMenuItem(); item.Image = host.ServerRunning && !host.VersionMismatch ? global::renderdocui.Properties.Resources.tick : global::renderdocui.Properties.Resources.cross; if (host.Connected) item.Text = String.Format("{0} (Connected)", host.Hostname); else if (host.ServerRunning && host.VersionMismatch) item.Text = String.Format("{0} (Bad Version)", host.Hostname); else if (host.ServerRunning && host.Busy) item.Text = String.Format("{0} (Busy)", host.Hostname); else if (host.ServerRunning) item.Text = String.Format("{0} (Online)", host.Hostname); else item.Text = String.Format("{0} (Offline)", host.Hostname); item.Click += new EventHandler(switchContext); item.Tag = host; // don't allow switching to the connected host if (host.Connected) item.Enabled = false; items[idx++] = item; } if(includeLocalhost && idx < items.Length) items[idx] = localContext; strip.Clear(); foreach(ToolStripItem item in items) if(item != null) strip.Add(item); }
public static void CreateScriptMenuItems(ToolStripItemCollection items, Action<ScriptDocument> clickHandler) { items.Clear(); foreach(ScriptDocument doc in CANAPEProject.CurrentProject.GetDocumentsByType(typeof(ScriptDocument))) { ToolStripItem item = items.Add(doc.Name); item.Click += (o, e) => clickHandler(doc); } }
/// <summary> /// Sorts the ToolStripItemCollection collection. /// </summary> /// <param name="items"></param> private void SortItems( ToolStripItemCollection items ) { List<ToolStripItem> specs; if (items == null || items.Count == 0) { return; } specs = new List<ToolStripItem>(); foreach (ToolStripItem item in items) { specs.Add(item); } specs.Sort(delegate( ToolStripItem a, ToolStripItem b ) { string sortA; string sortB; if (a.GetType().Equals(typeof(SortableToolStripMenuItem))) { sortA = ((SortableToolStripMenuItem)a).SortName; } else if (a.GetType().Equals(typeof(SortableToolStripSeparator))) { sortA = ((SortableToolStripSeparator)a).SortName; } else { sortA = string.Empty; } if (b.GetType().Equals(typeof(SortableToolStripMenuItem))) { sortB = ((SortableToolStripMenuItem)b).SortName; } else if (b.GetType().Equals(typeof(SortableToolStripSeparator))) { sortB = ((SortableToolStripSeparator)b).SortName; } else { sortB = string.Empty; } return string.Compare(sortA, sortB, StringComparison.InvariantCultureIgnoreCase); }); items.Clear(); foreach (ToolStripItem item in specs) { items.Add(item); } }
/// <summary> /// Create the menu items that will allow columns to be choosen and add them to the /// given collection /// </summary> /// <param name="items"></param> 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); } }
private void AddMenuItems(int currGroupIndex, ref int currentListIndex, ToolStripItemCollection currNodes, string prevGroupByField) { IList innerList = this.m_currencyManager.List; System.ComponentModel.PropertyDescriptor pdPrevGroupBy = null; string prevGroupByValue = null; SPTreeNodeGroup currGroup; if (prevGroupByField != "") { pdPrevGroupBy = this.m_currencyManager.GetItemProperties()[prevGroupByField]; } currGroupIndex++; if (treeGroups.Count > currGroupIndex) { currGroup = (SPTreeNodeGroup) (treeGroups[currGroupIndex]); PropertyDescriptor pdGroupBy = null; PropertyDescriptor pdValue = null; PropertyDescriptor pdDisplay = null; pdGroupBy = this.m_currencyManager.GetItemProperties()[currGroup.GroupBy]; pdValue = this.m_currencyManager.GetItemProperties()[currGroup.ValueMember]; pdDisplay = this.m_currencyManager.GetItemProperties()[currGroup.DisplayMember]; string currGroupBy = null; if (innerList.Count > currentListIndex) { if (pdPrevGroupBy != null) { prevGroupByValue = pdPrevGroupBy.GetValue(innerList[currentListIndex]).ToString(); } MenuStripItem myFirstNode = null; object currObject = null; while ((currentListIndex < innerList.Count) && (pdPrevGroupBy != null) && (pdPrevGroupBy.GetValue(innerList[currentListIndex]).ToString() == prevGroupByValue)) { currObject = innerList[currentListIndex]; if (pdGroupBy.GetValue(currObject).ToString() != currGroupBy) { currGroupBy = pdGroupBy.GetValue(currObject).ToString(); myFirstNode = new MenuStripItem(currGroup.Name, pdDisplay.GetValue(currObject).ToString(), currObject, pdValue.GetValue(innerList[currentListIndex]), currGroup.ImageIndex, currentListIndex); currNodes.Add(myFirstNode); } else { AddMenuItems(currGroupIndex, ref currentListIndex, this.Items, currGroup.GroupBy); } } } } else { MenuStripItem myNewLeafNode; object currObject = this.m_currencyManager.List[currentListIndex]; if ((this.DisplayMember != null) && (this.ValueMember != null) && (this.DisplayMember != "") && (this.ValueMember != "")) { PropertyDescriptor pdDisplayloc = this.m_currencyManager.GetItemProperties()[this.DisplayMember]; PropertyDescriptor pdValueloc = this.m_currencyManager.GetItemProperties()[this.ValueMember]; if (this.Tag == null) { myNewLeafNode = new MenuStripItem("", pdDisplayloc.GetValue(currObject).ToString(), currObject, pdValueloc.GetValue(currObject), currentListIndex); } else { myNewLeafNode = new MenuStripItem(this.Tag.ToString(), pdDisplayloc.GetValue(currObject).ToString(), currObject, pdValueloc.GetValue(currObject), currentListIndex); } } else { myNewLeafNode = new MenuStripItem("", currentListIndex.ToString(), currObject, currObject, currentListIndex, currentListIndex); } currNodes.Add(myNewLeafNode); currentListIndex++; } }