" );
output.Write( "" );
//
// Generate ancestor lines.
//
string lines = "";
TreeNode ancestor = node.Parent;
while( null != ancestor )
{
image = "line-ns.gif";
if( null == ancestor.Parent || ancestor.Index >= ancestor.Parent.Nodes.Count - 1 )
image = "blank.gif";
lines = "" + lines;
ancestor = ancestor.Parent;
}
output.Write( lines );
//
// Generate expand/collapse image.
//
bool north = false;
bool south = false;
if( null == node.Parent )
{
if( node.Index > 0 )
north = true;
if( node.Index < node.TreeView.Nodes.Count - 1 )
south = true;
}
else
{
north = true;
if( node.Index < node.Parent.Nodes.Count - 1 )
south = true;
}
//
// Determine which expander image we should use.
//
string dir = ( north ? "n" : "" ) + "e" + ( south ? "s" : "" );
if( node.Nodes.Count > 0 )
{
if( node.IsExpanded )
image = "minus-";
else
image = "plus-";
output.Write( "" );
}
else
output.Write( "" );
//
// Display the node image (or a blank image if none was specified).
//
if( null != node.ImageUrl )
{
output.Write( "" );
}
else
output.Write( "" );
//
// Display the node text.
//
output.Write( "" );
output.Write( "" );
output.Write( text + "
\n" );
count ++;
//
// Render this node's children.
//
foreach( TreeNode child in node.Nodes )
RenderNode( output, child );
output.WriteLine( "
" );
}
}
/// ********************************************************************
/// public class TreeNode
/// --------------------------------------------------------------------
///
///
/// ********************************************************************
///
public class TreeNode
{
internal protected TreeNode parent;
internal protected TreeView treeView;
internal protected TreeNodeCollection nodes;
protected bool expanded = false;
public string Text;
public string Key;
public string ImageUrl;
public string OpenImageUrl;
public string OnClick;
public string OnContextMenu;
public string Tooltip;
public TreeNode()
: this( null, null, null, null )
{
}
public TreeNode( string text )
: this( text, null, null, null )
{
}
public TreeNode( string text, string key )
: this( text, key, null, null )
{
}
public TreeNode( string text, string key, string imageUrl )
: this( text, key, null, null )
{
}
public TreeNode( string text, string key, string imageUrl, string openImageUrl )
{
this.Text = text;
this.Key = key;
this.ImageUrl = imageUrl;
this.OpenImageUrl = openImageUrl;
this.nodes = new TreeNodeCollection( this );
}
public string FullPath
{
get
{
string path = this.Text;
TreeNode node = this;
while( null != node.Parent )
{
node = node.Parent;
path = path + "\\" + node.Text;
}
return path;
}
}
public int Index
{
get
{
if( null == parent )
return treeView.Nodes.IndexOf( this );
return parent.Nodes.IndexOf( this );
}
}
public bool IsExpanded
{
get { return expanded; }
}
public bool IsSelected
{
get
{
if( null == treeView )
return false;
return treeView.SelectedNode == this;
}
}
public TreeNodeCollection Nodes
{
get { return nodes; }
}
public TreeNode Parent
{
get { return parent; }
}
public UDDI.Web.TreeView TreeView
{
get { return treeView; }
}
public void Collapse()
{
expanded = false;
}
public void EnsureVisible()
{
TreeNode node = this;
while( null != node.Parent )
{
node = node.Parent;
node.Expand();
}
}
public void Expand()
{
expanded = true;
}
public void Remove()
{
if( null != parent )
parent.Nodes.RemoveAt( Index );
}
public void Select()
{
treeView.SelectedNode = this;
}
public void Toggle()
{
expanded = !expanded;
}
}
/// ********************************************************************
/// public class TreeNodeCollection
/// --------------------------------------------------------------------
///
///
/// ********************************************************************
///
public class TreeNodeCollection : CollectionBase
{
protected TreeNode parent;
protected TreeView treeView;
internal protected TreeNodeCollection( TreeNode parent )
{
this.parent = parent;
this.treeView = parent.TreeView;
}
internal protected TreeNodeCollection( TreeView treeView )
{
this.parent = null;
this.treeView = treeView;
}
public TreeNode this[ int index ]
{
get { return (TreeNode)List[ index ]; }
set { List[ index ] = value; }
}
public TreeNode Add( string text )
{
return Add( text, null, null, null );
}
public TreeNode Add( string text, string key )
{
return Add( text, key, null, null );
}
public TreeNode Add( string text, string key, string imageUrl )
{
return Add( text, key, imageUrl, null );
}
public TreeNode Add( string text, string key, string imageUrl, string openImageUrl )
{
TreeNode node = new TreeNode( text, key, imageUrl, openImageUrl );
node.parent = this.parent;
node.treeView = this.treeView;
node.Nodes.treeView = this.treeView;
List.Add( node );
return node;
}
public int Add( TreeNode node )
{
node.parent = this.parent;
node.treeView = this.treeView;
node.Nodes.treeView = this.treeView;
return List.Add( node );
}
public int IndexOf( TreeNode node )
{
return List.IndexOf( node );
}
public void Remove( TreeNode node )
{
List.Remove( node );
}
}
}