Question

This is how my data is stored in database.

id    parentId      menu                   filename

1     0             Menu1     

2     1             Sub Menu 1.1     

3     0             Menu2     

4     3             Sub Menu2.1    

5     3             Sub Menu2.2  

6     5             My file                D:\a.txt

7     0             Menu 3     

8     7             My file (menu3)        D:\b.txt

I want to show the menu/submenu/filename on the Ribbon Control. If somebody has done something like this, please suggest how this can be done. I have created a Ribbon Form then Ribbon Control, Added Bar Button Item. Now here I want to show the menu with navigation arrow e.g.menu1, menu2, menu3 with navigation arrow which on hover shows sub menu and sub menu again showing the arrow if there are any child element in it.

Platform: VS2012, windows application, c#

Était-ce utile?

La solution 2

    private void AddMenu(string menuName, int id, int parentId, string fileName)
    {
        BarSubItem subitem = CreateSubItem(menuName, id, fileName);

        if (parentId != 0)
        {
            BarSubItem parentItem = ribbon.Items.FindById(parentId) as BarSubItem;
            parentItem.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo(subitem));
        }
        else
        {                
            menuBarSubItem.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo(subitem));
        }
    }

    private BarSubItem CreateSubItem(string menuName, int id, string fileName)
    {
        BarSubItem subitem = new BarSubItem(ribbon.Manager, menuName);
        subitem.Id = id;
        if (!string.IsNullOrEmpty(fileName))
            subitem.Glyph = System.Drawing.Image.FromFile("file.png");
        return subitem;
    }

    private void AddMenuItem(string menuName, int id, int parentId, string fileName)
    {
        BarButtonItem buttonItem = new BarButtonItem(ribbon.Manager, menuName);
        buttonItem.Id = id;
        buttonItem.Tag = fileName;
        buttonItem.ItemClick += buttonItem_ItemClick;

        if (!string.IsNullOrEmpty(fileName))
            buttonItem.Glyph = System.Drawing.Image.FromFile("file.png");
        if (parentId != 0)
        {
            BarSubItem parentItem = ribbon.Items.FindById(parentId) as BarSubItem;
            parentItem.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo(buttonItem));
        }
        else
        {
            menuBarSubItem.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo(buttonItem));                
        }
    }

Autres conseils

Take a look at The List of Bar Items and Links help-article.
According to this document, you should use the Menu(BarSubItem) item instead of Button(BarButtonItem) item to represented a submenu within the Ribbon.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top