Пример #1
0
		/// <summary>
		/// Retrieve a list of albums that are in the heirarchical path between the specified album and a node in the treeview.
		/// The node that is discovered as the ancestor of the album is assigned to the existingParentNode parameter.
		/// </summary>
		/// <param name="treeview">The treeview with at least one node added to it. At least one node must be an ancestor of the 
		/// specified album.</param>
		/// <param name="album">An album. This method navigates the ancestors of this album until it finds a matching node in the treeview.</param>
		/// <param name="existingParentNode">The existing node in the treeview that is an ancestor of the specified album is assigned to
		/// this parameter.</param>
		/// <returns>Returns a list of albums where the first album (the one returned by calling Pop) is a child of the album 
		/// represented by the existingParentNode treeview node, and each subsequent album is a child of the previous album.
		/// The final album is the same album specified in the album parameter.</returns>
		private static Stack<IAlbum> GetAlbumsBetweenTopLevelNodeAndAlbum(ComponentArt.Web.UI.TreeView treeview, IAlbum album, out TreeViewNode existingParentNode)
		{
			if (treeview.Nodes.Count == 0)
				throw new ArgumentException("The treeview must have at least one top-level node before calling the function GetAlbumsBetweenTopLevelNodeAndAlbum().");
			
			Stack<IAlbum> albumParents = new Stack<IAlbum>();
			albumParents.Push(album);

			IAlbum parentAlbum = (IAlbum) album.Parent;

			albumParents.Push(parentAlbum);

			// Navigate up from the specified album until we find an album that exists in the treeview. Remember,
			// the treeview has been built with the root node and the first level of albums, so eventually we
			// should find an album. If not, just return without showing the current album.
			while ((existingParentNode = treeview.FindNodeById(parentAlbum.Id.ToString(CultureInfo.InvariantCulture))) == null)
			{
				parentAlbum = parentAlbum.Parent as IAlbum;

				if (parentAlbum == null)
					break;

				albumParents.Push(parentAlbum);
			}

			// Since we found a node in the treeview we don't need to add the most recent item in the stack. Pop it off.
			albumParents.Pop();

			return albumParents;
		}