Re: Inheriting from the TreeNode class



Hey Alex,

Thanks for your response.
I've reviewed the code and performed some further tests. I think the cause
of the TreeNode not expand behavior is the "OnTreeNodeExpanded" event, we
must have an eventhandler for this event, otherwise, the TreeNode won't be
able to expand even if we configure PopuplateOnDemand for treeNode and
registered the TreeNodePopulated event handler...

Also, this is the TreeView's default behavior , not specific to our custom
TreeView implementation...

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Alexander Walker" <alex@xxxxxxxxxxxxxxx>
| References: <#7WFWGZGGHA.3100@xxxxxxxxxxxxxxxxxxxx>
<CSxlZblGGHA.3944@xxxxxxxxxxxxxxxxxxxxx>
<uM#Je5HHGHA.140@xxxxxxxxxxxxxxxxxxxx>
<Ign3#IKHGHA.3152@xxxxxxxxxxxxxxxxxxxxx>
<O6OxfzfHGHA.3728@xxxxxxxxxxxxxxxxxxxx>
| Subject: Re: Inheriting from the TreeNode class
| Date: Fri, 20 Jan 2006 20:13:33 -0000
| Lines: 127
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <eZBr$3fHGHA.532@xxxxxxxxxxxxxxxxxxxx>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: 81-6-217-221.gotadsl.co.uk 81.6.217.221
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:32692
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| I forgot to mention that I also set the PopulateOnDemand property of the
nodes
| to true and the ExpandDepth to 2
|
| To avoid any confusion I will include the source here
|
| =================aspx===========
|
| <%@ Page Language="C#" AutoEventWireup="true"
CodeFile="CustTreeView.aspx.cs"
| Inherits="CustTreeView" %>
|
| <%@ Register Assembly="WebControlLib" Namespace="WebControlLib"
TagPrefix="cc1"
| %>
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
| <html xmlns="http://www.w3.org/1999/xhtml";>
| <head id="Head1" runat="server">
| <title>Untitled Page</title>
| </head>
| <body>
| <form id="form1" runat="server">
| <div>
| <cc1:CustomTreeView ID="CustomTreeView1" runat="server"
| ExpandDepth="2"
OnSelectedNodeChanged="CustomTreeView1_SelectedNodeChanged"
| EnableClientScript="true"
OnTreeNodePopulate="CustomTreeView1_TreeNodePopulate">
| <nodes>
|
| <cc1:CustomTreeNode Text="Node1" Value="Node1"
| SelectAction="SelectExpand" >
| <cc1:CustomTreeNode Text="Node11" Value="Node11"
| SelectAction="SelectExpand" ></cc1:CustomTreeNode>
| <cc1:CustomTreeNode Text="Node12"
| Value="Node12"></cc1:CustomTreeNode>
| <cc1:CustomTreeNode Text="Node13"
| Value="Node13"></cc1:CustomTreeNode>
| </cc1:CustomTreeNode>
| <cc1:CustomTreeNode Text="Node2" Value="Node2">
| <cc1:CustomTreeNode Text="Node21" Value="Node21"
| PopulateOnDemand="True" CustomInt="0" ></cc1:CustomTreeNode>
| <cc1:CustomTreeNode Text="Node22" Value="Node22"
| PopulateOnDemand="True" CustomInt="1"></cc1:CustomTreeNode>
| </cc1:CustomTreeNode>
| </nodes>
| </cc1:CustomTreeView>
| </div>
| </form>
| </body>
| </html>
|
| ========code behind===========
| using System;
| using System.Data;
| using System.Configuration;
| using System.Collections;
| using System.Web;
| using System.Web.Security;
| using System.Web.UI;
| using System.Web.UI.WebControls;
| using System.Web.UI.WebControls.WebParts;
| using System.Web.UI.HtmlControls;
|
| public partial class CustTreeView : System.Web.UI.Page
| {
| protected void Page_Load(object sender, EventArgs e)
| {
|
| }
|
| protected void CustomTreeView1_SelectedNodeChanged(object sender,
EventArgs
| e)
| {
| Response.Write("<br/>CustomTreeView1_SelectedNodeChanged ");
| WebControlLib.CustomTreeNode cn = CustomTreeView1.SelectedNode as
| WebControlLib.CustomTreeNode;
| Response.Write("<br/>Node.CustomInt: " + cn.CustomInt);
| Response.Write("<br/>Node.CustomInt: " + cn.CustomInt);
| }
|
| protected void CustomTreeView1_TreeNodePopulate(object
| sender,TreeNodeEventArgs e)
| {
| Response.Write("<br/>CustomTreeView1_TreeNodePopulate ");
| WebControlLib.CustomTreeNode cn = e.Node as
| WebControlLib.CustomTreeNode;
| Response.Write("<br/>Node.CustomInt: " + cn.CustomInt);
| //Response.Write("<br/>Node.CustomInt2: " + cn.CustomInt2);
| //Response.Write("<br/>Node.CustomInt3: " + cn.CustomInt3);
| //Response.Write("<br/>Node.CustomInt4: " + cn.CustomInt4);
|
| for (int i = 0; i < 5; i++)
| {
| WebControlLib.CustomTreeNode ncn = new
| WebControlLib.CustomTreeNode();
| ncn.Text = "New Child Node " + i;
| ncn.Value = i.ToString();
| ncn.PopulateOnDemand = true;
| ncn.CustomInt = i;
|
| cn.ChildNodes.Add(ncn);
| }
| }
| }
|
|
| Thanks again
|
| Alex
|
| "Alexander Walker" <alex@xxxxxxxxxxxxxxx> wrote in message
| news:O6OxfzfHGHA.3728@xxxxxxxxxxxxxxxxxxxxxxx
| | Hello Steve
| |
| | Thank you for your response
| |
| | I built your example and it worked. I altered it slightly so that it
was more
| | like the implementation I have in my application and it stopped working.
| | Specifically the nodes did not expand any more. I removed the
| OnTreeNodeExpanded
| | event and set the EnableClientScript property to true on the aspx page,
if you
| | try this, I think that you will get the same behaviour that I
described in my
| | previous message
| |
| | Thanks
| |
| | Alex
| |
|
|
|

.