This project has moved and is read-only. For the latest updates, please go here.

Sample Code

Oct 14, 2009 at 1:38 PM
Edited Oct 14, 2009 at 1:40 PM


Could you please add some more samplecode? I try to get the dropdown buttons to work but cannot find where to add the items.

I tried someyhing like:

            Crumbs.Address.PathSeparator = Path.DirectorySeparatorChar.ToString();
            Crumbs.Address.FullPath = textBox1.Text;
            Crumbs.Address.Nodes.Add(new BreadcrumbBarNode("node1", "value", MyEventHandler, 11));
            Crumbs.Address.Nodes.Add(new BreadcrumbBarNode("node2", "value", MyEventHandler, 12));
            //((BreadcrumbBarNode)Crumbs.Address.Nodes[Crumbs.Address.Nodes.Count - 1]).DropDownMenuOpening += MyCancelEventHandler;
            //((BreadcrumbBarNode)Crumbs.Address.Nodes[Crumbs.Address.Nodes.Count - 1]).ContextMenu.MenuItems.Add(new MenuItem("test"));
                //AddDropDownItem(new BreadcrumbDropDownItem("test1"));
            ((BreadcrumbBarNode)Crumbs.Address.Nodes[Crumbs.Address.Nodes.Count - 1]).AddDropDownItem(new BreadcrumbDropDownItem("test2"));
            ((BreadcrumbBarNode)Crumbs.Address.Nodes[Crumbs.Address.Nodes.Count - 2]).Enabled = true;
            ((BreadcrumbBarNode)Crumbs.Address.Nodes[Crumbs.Address.Nodes.Count - 1]).Enabled = true;

but nothing shows up other than two new nodes 'node1' and 'node2'.

Any suggestions?

Oct 14, 2009 at 1:44 PM

The following code pops up a context menu for the last node (but still no dropdown on the button).

            ((BreadcrumbBarNode)Crumbs.Address.Nodes[Crumbs.Address.Nodes.Count - 1]).ContextMenu = new ContextMenu();
            ((BreadcrumbBarNode)Crumbs.Address.Nodes[Crumbs.Address.Nodes.Count - 1]).ContextMenu.MenuItems.Add(new MenuItem("TEST"));

Oct 14, 2009 at 2:01 PM


Digging  & Debugging into the code reveals that:

1) BreadCrumbBarNode.AddDropDownItem adds items to the DropDownMenuItems object.
2) The BreadCrumbBarNode.OnMouseDown shows the DropDownMenu which has no items even after a call to AddDropDownItems,

Oct 14, 2009 at 2:30 PM
Edited Oct 14, 2009 at 2:40 PM


Found where things where going wrong. In BuildDropDownMenu there where three bugs.

1) The tsmi ToolStropMenuItem's created from the DropDownMenuItems collection where never added to teh DropDownMenu so it stayed empty
2) There was no safeguard against i.Tag being null (which happened in the original code).
3) At this point things started to show up when clicked, but the delegate code would still crash.
    Looking at the code faulting in 2) it also was neccesary to assign item to the tsmi.Tag property instead of using item.Tag 
    Which was/is most of the time 0 and cannot be cast into the BreadcrumbDropDownItem expected in the delegate code.

I also removed the Tag property at the top of the file as VS2008 was complaining it was hiding a inhertited one (from Control).

The delegate code in BuildDropDown menu could also test for the Tag being an object of the BreadcrumbDropDownMenuItem class (added it already in the code below). The bbdi.Tag then contains the value passed in the BreadcrumbDropDownMenuItem constructor.

Final code:

        private void BuildDropDownMenu()
            foreach (BreadcrumbDropDownItem item in this.DropDownMenuItems)
                ToolStripMenuItem tsmi = new ToolStripMenuItem(item.Text, item.Image,
                    delegate(object s, EventArgs e1)
                        ToolStripMenuItem i = s as ToolStripMenuItem;
                        //veg: Added safeguard for Tag being null and of the wrong type
                        if (i.Tag != null && i.Tag is BreadcrumbDropDownItem)
                            BreadcrumbDropDownItem bddi = i.Tag as BreadcrumbDropDownItem;
                            if (bddi.NavigateDelegate != null)
                                bddi.NavigateDelegate.Invoke(bddi, EventArgs.Empty);
                    }, item.Text);
                //veg: Changed from item.Tag to item.
                tsmi.Tag = item;

                //veg: Add.

Oct 30, 2009 at 1:10 PM

Thanks, i will get this fixed. This project is mainly used for another project I am working on. It's not dead, I just am not fully implementing all of the features yet, so once I get to doing more with the address bar, this project will "pick up speed" a bit.

Oct 30, 2009 at 1:10 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Dec 1, 2009 at 3:58 PM


Any progress on some sample code? I would like to use the control in a new project but still do not know how to properly add/fill the dropdown menu's