Version

Add Groups Using Code

There are several ways to add Groups to WinExplorerBar™ at run time. Groups are contained by the element’s Groups collection, and you can use standard collection methods to add and work with Groups. Groups are also part of the element’s layout, and can be created by restoring a layout that has been saved to a binary or XML file.

Use one of the following methods to add Groups to the element:

  • Groups collection Add method - You can add Groups to the element by invoking the Add method. The Add method will return the newly added Group, which you can then use to set any Group-related properties. You can also use the Add method to create the new Group with a specific Text and/or Key value.

The code below illustrates several ways of using the Add method:

In Visual Basic:

Imports Infragistics.Win.UltraWinExplorerBar
...
Private Sub Add_Groups_Using_Code_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
	Dim aGroup As UltraExplorerBarGroup
	aGroup = Me.UltraExplorerBar1.Groups.Add
	aGroup.Text = "Employees Info"
	aGroup.Key = "g_EmployeesInfo"
	aGroup = Me.UltraExplorerBar1.Groups.Add("g_DepartmentInfo")
	aGroup.Text = "Department Info"
	Me.UltraExplorerBar1.Groups.Add("g_Benefits", "Benefits")
End Sub

In C#:

using Infragistics.Win.UltraWinExplorerBar;
...
private void Add_Groups_Using_Code_Load(object sender, EventArgs e)
{
	UltraExplorerBarGroup aGroup = new UltraExplorerBarGroup();
	aGroup = this.ultraExplorerBar1.Groups.Add();
	aGroup.Text = "Employees Info";
	aGroup.Key = "g_EmployeesInfo";
	aGroup = this.ultraExplorerBar1.Groups.Add("g_DepartmentInfo");
	aGroup.Text = "Department Info";
	this.ultraExplorerBar1.Groups.Add("g_Benefits", "Benefits");
}
resulting ultraexplorerbar based on code above.
  • Groups collection AddRange method - The Groups collection also supports an AddRange method that can be used to add multiple Groups at once from an array of Group objects. This method provides functionality consistent with the .NET form generator code for instantiating elements.

  • Load Groups from Saved Layout - The WinExplorerBar can save its group and item information in either an XML or a binary file. You can later load this file into the element to restore the Groups that previously existed, as well as setting any other saved attributes.

  • You can also add groups at design time. For information, see the topic Add Groups and Items at Design Time.