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

Dynamically adding NavBarGroup

Sep 7, 2007 at 4:05 AM
I'm new to DevExpress and have only been working with SCSF for a couple of months. I've placed a NavBarWorkspace on the left of my shell form. I'd like to trigger the filling of a NavBarGroup using a menu option or toolstrip but am having trouble finding my way around. For now I have a single business module which registers two menu items - people and households. When one of the menu items is clicked the first time, I'd like to programatically create the appropriate NavBarGroup and then put a list view inside of it (e.g. a list of persons). Does someone have a code sample to share? The BankTeller sample has its two groups created at design time whereas I'd like modules to add them as needed.

Sep 8, 2007 at 10:56 AM
Excellent question.
The NavBarWorkspace's NavBarGroups should probably always be constructed in code rather than at design time. I had to go through the same thinking process when I first used it.
It is my intention to change the sample app to do this, I just haven't got around to it yet.
It looks like you need a level of dynamicness, that is even one-more than I need. I create all the NavBarGroups on ModuleInit, nothing after that., but the same code should still suit you as far as I can see.

Sep 8, 2007 at 12:25 PM
Edited Sep 9, 2007 at 1:59 AM
This should give you a rough idea.
In this case, I'm using a CustomContainer in my Group, rather than populating it with NavBarItems.

NavBarGroup group = new NavBarGroup();
group.GroupStyle = NavBarGroupStyle.ControlContainer;
group.Expanded = true;
group.Caption = "Statistics";
group.GroupCaptionUseImage = NavBarImage.Large;
UIExtensionSite mainNavBarWorkspace = _rootWorkItem.UIExtensionSites[UIExtensionNames.NavBarWorkspace];
_rootWorkItem.UIExtensionSites.RegisterSite(UIExtensionNames.MyNavBarGroup, new NavBarItemCollectionUIAdapter(group));
MyNavBarTree navbarTreeView = _rootWorkItem.SmartParts.AddNew<MyNavBarTree>("NewFantasticNavBar");
navbarTreeView.Dock = DockStyle.Fill;
NavBarGroupControlContainer controlContainer = new NavBarGroupControlContainer();
group.ControlContainer = controlContainer;
Sep 8, 2007 at 4:37 PM
Woo-hoo! I'm still digesting what you did but it works. I was already heading down the path of UIExtensionSites but somehow my shoe laces got tied up and I fell down!

I'm now looking at how I can make the newly added group be the "selected" one - adding the first works, adding the second doesn't automatically expand it even though .expanded = true;

Also, I'm rooting around in the collections trying to figure out how to programatically "click" the collapsed group when the user selects the toolbar item again. IOW, once created I want to bring the navBarGroup into "focus" when the user clicks the toolbar item a second time.

PandaWood wrote:
This should give you a rough idea.
In this case, I'm using a CustomContainer in my Group, rather than populating it with NavBarItems.

Jan 13, 2008 at 11:47 AM
Edited Jan 20, 2008 at 12:07 AM
I just discovered that the code I've supplied to you in the previous post, is not actually what the author of the XtraNavBarWorkspace intended.

I just committed changes to the BankTeller Applicaton which adds NavBarGroups, in code, using the intended method (see BankTellerWorkItem.cs).

Basically, the intended method is to not use an ExtensionSite for the NavBar, but to just call navbarWorkspace.Show(smartpart, spInfo);

So, previously, I thought you would do something like this:
private void CreateNavBarGroups()
	NavBarGroup customerGroup = new NavBarGroup();
	customerGroup.Expanded = true;
	customerGroup.Caption = "Customers";
	customerGroup.GroupCaptionUseImage = NavBarImage.Large;
	customerGroup.LargeImage = global::BankTellerModule.Properties.Resources.customersLarge;
	customerGroup.SmallImage = global::BankTellerModule.Properties.Resources.customersSmall;
	// if we had more than one module, the code below to add a group, could be run from any module
	NavBarGroup statsGroup = new NavBarGroup();
	statsGroup.Expanded = true;
	statsGroup.Caption = "Statistics";
	statsGroup.GroupCaptionUseImage = NavBarImage.Large;
	statsGroup.LargeImage = global::BankTellerModule.Properties.Resources.statsLarge;
	statsGroup.SmallImage = global::BankTellerModule.Properties.Resources.statsSmall;
	UIExtensionSite navBarWorkspace = workItem.UIExtensionSites[UIExtensionSites.NavBar];
        //... plus a bit more work here if you want to use a ControlContainer

However, some of this is unnecessary if you use the Show method of the XtraNavBarWorkspace because it will create a NavBarGroup for you, using the ControlContainer style and it uses the smartpartInfo passed, to determine the Caption , SmallImage and LargeImage.

XtraNavBarGroupSmartPartInfo customerInfo = new XtraNavBarGroupSmartPartInfo();
customerInfo.Title = "Customers";
customerInfo.LargeImage = global::BankTellerModule.Properties.Resources.customersLarge;
customerInfo.SmallImage = global::BankTellerModule.Properties.Resources.customersSmall;
XtraNavBarGroupSmartPartInfo statsInfo = new XtraNavBarGroupSmartPartInfo();
statsInfo.Title = "Statistics";
statsInfo.LargeImage = global::BankTellerModule.Properties.Resources.statsLarge;
statsInfo.SmallImage = global::BankTellerModule.Properties.Resources.statsSmall;
navbarWorkspace.Show(customerView, customerInfo);
navbarWorkspace.Show(statsBarView, statsInfo);

The ExtensionSite method still works, though. Nothing to worry about.
Jan 30, 2008 at 1:21 PM
Incidentally, given the way the TabWorkspace works, the intended method I refer to in the post above, is absolutely right to use the Show() method to add NavBarGroups. At least, it's consistent with CAB.