Why is an Index out of range when deriving from TreeView?


D

David

Help!!!

//
// Contents of ValueNode.cs
//

using System;

using Microsoft.Web.UI.WebControls;

namespace TreeNodeProblem
{
/// <summary>
/// Summary description for ValueNode.
///
/// Warning: Use of this class may cause hypertension and various neurotic
disorders.
///
/// </summary>
public class ValueNode : TreeNode
{
public ValueNode() : base()
{
Text = "value";
}
}
}


//
// Contents of XNode.cs
//
using System;
using Microsoft.Web.UI.WebControls;

namespace TreeNodeProblem
{
/// <summary>
/// Summary description for XNode.
/// </summary>
public class XNode : TreeNode
{
public XNode() :base()
{
}
public XNode(string XStr) :base()
{
Text = XStr;
if(XStr == "Works")
{
TreeNode n = new TreeNode();
n.Text = "value";
Nodes.Add(n);
}
else
{
ValueNode n = new ValueNode();
Nodes.Add(n);
}
}
}
}

//
// Contents of WebForm1.aspx.cs
//

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
//
//
// Added Line:
using Microsoft.Web.UI.WebControls;

namespace TreeNodeProblem
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView tv;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
tv.AutoPostBack = true;
//
tv.Nodes.Add(new XNode("Works"));
//tv.Nodes.Add(new XNode("DoesNotWork"));

}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}


The WebForm1.aspx file HTML

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="TreeNodeProblem.WebForm1" %>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls"
Assembly="Microsoft.Web.UI.WebControls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<iewc:TreeView id="tv" style="Z-INDEX: 101; LEFT: 288px; POSITION:
absolute; TOP: 200px" runat="server"></iewc:TreeView>
</form>
</body>
</HTML>
 
Ad

Advertisements

A

Alvin Bruney

What line is the exception coming from? You need to give some more
specifics.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top