Version

Lazily Populate WinNavigationBar

A quick and efficient method of adding Locations to the WinNavigationBar™ is to lazily populate the Locations. The term "lazily" is coined because you are only doing the minimum amount of work necessary to display the desired Locations to your end user. We’ve exposed a convenient event, the InitializeLocations event, which allows you to populate a location’s children when you first access it. This event fires only once per Location collection, unless you call the Location’s Reset method. For more information on resetting Locations, see Refresh WinNavigationBar’s Locations.

The following code demonstrates how you could populate each Location with directory information. This code will run the first time you access each Location. The beauty of this event really shows when the end user types in a path while WinNavigationBar is in edit mode. When the end user types in a new path, WinNavigationBar parses that path. As each item in the path is parsed (remember, these items are separated by the PathSeparator ), the InitializeLocations event fires for that item, therefore creating a location, preventing the NavigationPathParseError event from firing.

In Visual Basic:

Imports Infragistics.Win.Misc
Imports Infragistics.Win.Misc.UltraWinNavigationBar
Private Sub UltraNavigationBar1_InitializeLocations(ByVal sender As System.Object, _
    ByVal e As InitializeLocationsEventArgs) _
    Handles UltraNavigationBar1.InitializeLocations
    ' Get the full path of the parent location.
    Dim path As String = _
        e.ParentLocation.GetFullPath(FullPathFormat.EditMode)
    ' Populate an array of DirectoryInfos with the
    ' subdirectories of the parent location's path.
    Dim dirs As System.IO.DirectoryInfo() = _
        New System.IO.DirectoryInfo(path + "\\").GetDirectories()
    ' Loop through each subdirectory...
    For Each dir As System.IO.DirectoryInfo In dirs
        ' ...add a new location for WinNavigationBar.
        ' The subdirectory's full path will be the key
        ' and the name will be the Text.
        e.ParentLocation.Locations.Add(dir.FullName, dir.Name)
    Next
End Sub

In C#:

using Infragistics.Win.Misc;
using Infragistics.Win.Misc.UltraWinNavigationBar;
private void ultraNavigationBar1_InitializeLocations
  (object sender, InitializeLocationsEventArgs e)
{
	// Get the full path of the parent location.
	string path =
		e.ParentLocation.GetFullPath(FullPathFormat.EditMode);
	// Populate an array of DirectoryInfos with the
	// subdirectories of the parent location's path.
	System.IO.DirectoryInfo[] dirs =
		new System.IO.DirectoryInfo(path + "\\").GetDirectories();
	// Loop through each subdirectory...
	foreach (System.IO.DirectoryInfo dir in dirs)
	{
		// ...add a new location for WinNavigationBar.
		// The subdirectory's full path will be the key
		// and the name will be the Text.
		e.ParentLocation.Locations.Add(dir.FullName, dir.Name);
	}
}