Barmanager.menu (Barsubitem)

Source: Internet
Author: User

DevExpress's help document is too scarce, his own help is simply described, no sample, and the online Help on its website only uses its designer toolbar, PopupMenu, without exploiting the code.
Although it is possible to take advantage of code development, you can refer to the code behind the designer, but there are some differences. I have recently encountered a problem:
I initialize the Barbuttonitem,barsubitem button instance through reflection, and finally add these buttons to the toolbar on the main program:
This method is used when instantiating a barsubitem with reflection:
Barsubitem newitem = new Barsubitem ();
Newitem.name = Intmenuitemcount.tostring ();
Newitem.id = intmenuitemcount++;
NEWMENU.LINKSPERSISTINFO.ADD (New DevExpress.XtraBars.LinkPersistInfo ((Baritem) item, begingroup));
Here to note:
1, the ID must be unique.
2, do not use Newmenu.additem ((Baritem) item), this method will cause a lot of problems, such as: BeginGroup menu grouping can not be implemented, I tried to implement by the following methods, but still in vain, and some Edit menu can not use this method, Example: Bartoolbarslistitem Toolbar List Menu
Baritemlink Itemlink = Newmenu.additem ((baritem) item);
Itemlink.begingroup = BeginGroup;
3, after the instantiation of the Barsubitem added to toolbar, but also recursive Barsubitem and its sub-menu to join the Barmanager.
private void AddMenuItem (DevExpress.XtraBars.BarItem menuItem)
{
if (MenuItem! = null)
{
If you are using the Edit box toolbar
if (MenuItem is Baredititem)
{
This. BARMENUMANAGER.REPOSITORYITEMS.ADD (MenuItem as Baredititem). Edit);
}
This. BARMENUMANAGER.ITEMS.ADD (MenuItem);
if (MenuItem is DevExpress.XtraBars.BarSubItem)
{
DevExpress.XtraBars.LinksInfo Linksinfo = (MenuItem as DevExpress.XtraBars.BarSubItem). Linkspersistinfo;
for (int i = 0; i < Linksinfo.count; i++)
{
AddMenuItem (Baritem) linksinfo[i]. Item);
}
}
}
4, if the right-click menu is also implemented through reflection, you need to be aware of loading the context menu:
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);
With Linkspersistinfo Right-click menu does not come out
CONTEXTMENU.LINKSPERSISTINFO.ADD (New Linkpersistinfo (Baritem, BeginGroup));
Baritemlink Itemlink = Contextmenu.additem (Baritem);
Itemlink.begingroup = BeginGroup;
}
}
Contextmenu.manager = Barmanager;
return contextMenu;
}
Note Baritemlink Itemlink = (MenuItem as Barsubitem) in this method. AddItem (item); This method appears to add a menu, but in practice, if you do not use this method, the menu in the right-click menu will not display if it has a submenu. I just let this problem take a lot of my business.

private void AddMenuItem (DevExpress.XtraBars.BarManager barmanager,devexpress.xtrabars.baritem MenuItem)
{
if (MenuItem! = null)
{
BARMANAGER.ITEMS.ADD (MenuItem);
if (MenuItem is DevExpress.XtraBars.BarSubItem)
{
DevExpress.XtraBars.LinksInfo Linksinfo = (MenuItem as DevExpress.XtraBars.BarSubItem). Linkspersistinfo;
int count = Linksinfo.count;
for (int i = 0; i < count; i++)
{
Baritem item = (Baritem) linksinfo[i]. Item;
                         item. Manager = Barmanager;

Baritemlink Itemlink = (MenuItem as Barsubitem). AddItem (item);
Itemlink.begingroup = Linksinfo[i]. BeginGroup;
AddMenuItem (Barmanager, item);
}
}
}
}

Barmanager.menu (Barsubitem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.