corrected rendering: styles are applied correct
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / TreeNode.cs
index 1ac0aca8f1540aac8db129f08a1c4aeced12d75f..5d6352b3e4ce9cf54a2b2903b16258ce40d145b4 100644 (file)
@@ -134,6 +134,8 @@ namespace System.Web.UI.WebControls
                                if (nodes != null)
                                        nodes.SetTree (tree);
                                ResetPathData ();
+                               if (PopulateOnDemand && !Populated && Expanded.HasValue && Expanded.Value)
+                                       Populate ();
                        }
                }
                
@@ -182,18 +184,10 @@ namespace System.Web.UI.WebControls
                public TreeNodeCollection ChildNodes {
                        get {
                                if (nodes == null) {
-                                       if (PopulateOnDemand && tree == null)
-                                               return null;
-
                                        nodes = new TreeNodeCollection (this);
                                                
                                        if (IsTrackingViewState)
                                                ((IStateManager)nodes).TrackViewState();
-                                       
-                                       if (PopulateOnDemand && !Populated) {
-                                               Populated = true;
-                                               Populate ();
-                                       }
                                }
                                return nodes;
                        }
@@ -209,6 +203,8 @@ namespace System.Web.UI.WebControls
                                ViewState ["Expanded"] = value;
                                if (tree != null)
                                        tree.NotifyExpandedChanged (this);
+                               if (PopulateOnDemand && !Populated && value.HasValue && value.Value)
+                                       Populate ();
                        }
                }
 
@@ -433,6 +429,10 @@ namespace System.Web.UI.WebControls
                
                internal void Populate ()
                {
+                       if (tree == null)
+                               return;
+
+                       Populated = true;
                        tree.NotifyPopulateRequired (this);
                }
                
@@ -481,7 +481,7 @@ namespace System.Web.UI.WebControls
                        bool? value = Expanded;
                        Expanded = value.HasValue ? !value.Value : true;
 #else
-                       Expanded = !Expanded;
+                       Expanded = !Expanded.GetValueOrDefault(false);
 #endif
                }
 
@@ -550,6 +550,8 @@ namespace System.Web.UI.WebControls
                internal void SetDirty ()
                {
                        ViewState.SetDirty (true);
+                       if (nodes != null)
+                               nodes.SetDirty ();
                }
                
                public virtual object Clone ()
@@ -711,15 +713,15 @@ namespace System.Web.UI.WebControls
                }
                                
                internal bool IsParentNode {
-                       get { return ChildNodes.Count > 0 && Parent != null; }
+                       get { return !IsRootNode && (ChildNodes.Count > 0 || PopulateOnDemand); }
                }
                
                internal bool IsLeafNode {
-                       get { return ChildNodes.Count == 0; }
+                       get { return !IsRootNode && ChildNodes.Count == 0 && !PopulateOnDemand; }
                }
                
                internal bool IsRootNode {
-                       get { return ChildNodes.Count > 0 && Parent == null; }
+                       get { return Depth == 0; }
                }
                
                TreeNodeBinding GetBinding ()