示例中是:
private DevExpress.XtraBars.PopupMenu popupMenu1; 添加一些項: ((System.ComponentModel.ISupportInitialize)(this.popupMenu1)).BeginInit(); this.popupMenu1.LinksPersistInfo.AddRange(new DevExpress.XtraBars.LinkPersistInfo[] { new DevExpress.XtraBars.LinkPersistInfo(this.iCut), new DevExpress.XtraBars.LinkPersistInfo(this.iCopy), new DevExpress.XtraBars.LinkPersistInfo(this.iPaste), new DevExpress.XtraBars.LinkPersistInfo(this.iClear), new DevExpress.XtraBars.LinkPersistInfo(this.iFont, true), new DevExpress.XtraBars.LinkPersistInfo(this.iBullets)}); ((System.ComponentModel.ISupportInitialize)(this.popupMenu1)).EndInit(); 加入BeginInit 和 EndInit 才能正確顯示
后來看到后面的博文,變通下,用這個方法:
popupMenu1.AddItem(new 一個 item);
如果加載已有的項目,則用:
popupMenu1.AddItem(new DevExpress.XtraBars.LinkPersistInfo(this.iCut).Item);
以下轉自:http://www.cnblogs.com/cglNet/archive/2012/08/27/2658207.html
原文:DevExpress 組件動態在PopupMenu中添加項
由於使用DevExpress 的控件,需要在PopupMenu動態添加項。根據PopupMenu的后台代碼,自己寫怎么添加都不顯示,不知道原因何在。代碼如下: BarButtonItem tBBI = new BarButtonItem(); tBBI.Name = "Item1"; tBBI.Caption = "myItem"; this.barManager1.Items.Add(tBBI); this.pPop.LinksPersistInfo.Add(new LinkPersistInfo(tBBI)); 后來無意中,發現PopupMenu有一個AddItem方法,用了之后,可以了。很高興。但問題接踵而至。按鈕中的項,不能分組。繼續找原因。知道發現這篇博客: http://www.cnblogs.com/supermap/archive/2006/07/01/440418.html 很受啟發,尤其是關鍵代碼 public PopupMenu CreateContextMenu() { PopupMenu contextMenu = new PopupMenu(); contextMenu.Popup += new EventHandler(ContextMenuPopupHandler); foreach (object item in buildItems) { if (item is BarItem) { bool beginGroup = false; beginGroup = (bool)(item as BarItem).Tag; //contextMenu.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo((item as BarItem), beginGroup) }); BarItem barItem = item as BarItem; AddMenuItem(barManager, barItem); //用LinksPersistInfo右鍵菜單不出來 //contextMenu.LinksPersistInfo.Add(new LinkPersistInfo(barItem, beginGroup)); BarItemLink itemLink = contextMenu.AddItem(barItem); itemLink.BeginGroup = beginGroup; } } contextMenu.Manager = barManager; return contextMenu; }
另外一篇文章:http://www.cnblogs.com/supermap/archive/2006/07/01/440418.html
http://www.cnblogs.com/supermap/archive/2006/07/01/440418.html