DevExpress 组件动态在PopupMenu中添加项
示例中是:
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