-
TreePanel and child
hi,
i've a database with some fields (key, father, title, ecc...). i need to put them in a treepanel searching foreach parentnode child.
Code:
[...]
myRows = dt.Select();
for (int p = 0; p < myRows.Length; p++)
{
Ext.Net.TreeNode parentNode;
if (myRows[p]["FATHER"].ToString() == "")
{
// Create Parent Node if field "FATHER" is null
parentNode = new Ext.Net.TreeNode();
parentNode.Text = myRows[p]["TITLE"].ToString();
parentNode.Icon = Ext.Net.Icon.Application;
parentNode.NodeID = myRows[p]["KEY"].ToString();
root.Nodes.Add(parentNode);
}
else
{
foreach (Ext.Net.TreeNode nodo in root.Nodes.) // create childnodeID
{
if (nodo.NodeID == myRows[p]["FATHER"].ToString())
{
//Ext.Net.TreeNode nodo = root.Nodes[0];
Ext.Net.TreeNode childNode = new Ext.Net.TreeNode();
childNode.Text = myRows[p]["TITLE"].ToString();
childNode.NodeID = myRows[p]["KEY"].ToString();
nodo.Nodes.Add(childNode);
}
}
This code works, but i need to populate tree in each level of child, with a recursive method, or something like that.
I hope that I was well expressed, and sorry for my bad english ^^
-
-
Hi,
I tried to use PageTreeLoader, but i see only root, i'm not able to see children with my code...
-
I'm afraid I don't understand the problem. Please clarify.
-
I want to see a trepanel with each sublevel, but with my first code i see only first and second level. Can I post some screen?
-
I don't think a screen-shot helps in that case.
Please provide a simple example to reproduce the problem.
-
Ok,
Page .aspx.cs
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Windows.Forms;
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;
using System.Data.OleDb;
using System.ComponentModel;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using Ext.Net;
using GoalManager.UserCs;
using GoalManager.Common;
public partial class gm_usercs_Main : System.Web.UI.Page
{
DataSet dprogetti, dpubbliche, dgestionali;
protected void Page_Load(object sender, EventArgs e)
{
ActionPlanList apList = new ActionPlanList();
dprogetti = (DataSet)apList.list(-10);
dpubbliche = (DataSet)apList.list(-11);
dgestionali = (DataSet)apList.list(-16);
DataTable TableProgetti = dprogetti.Tables[dprogetti.Tables[0].TableName];
DataTable TablePubbliche = dpubbliche.Tables[dpubbliche.Tables[0].TableName];
DataTable TableGestionali = dgestionali.Tables[dgestionali.Tables[0].TableName];
Ext.Net.TreePanel tree = new Ext.Net.TreePanel();
tree.Icon = Ext.Net.Icon.Application;
tree.RootVisible = false;
Ext.Net.TreeNode root = new Ext.Net.TreeNode();
tree.Root.Add(root);
foreach (DataRow RowPubbliche in TableProgetti.Rows)
{
int key = Convert.ToInt32(RowPubbliche["KEY"]);
ActionPlanList apList1 = new ActionPlanList();
DataSet ds;
ds = (DataSet)apList1.listTree(key);
DataTable dt = ds.Tables[ds.Tables[0].TableName];
DataRow[] myRows;
myRows = dt.Select();
for (int p = 0; p < myRows.Length; p++)
{
Ext.Net.TreeNode parentNode;
if (myRows[p]["FATHER"].ToString() == "")
{
// Create Parent Node
parentNode = new Ext.Net.TreeNode();
parentNode.Text = myRows[p]["TITLE"].ToString();
parentNode.Icon = Ext.Net.Icon.Application;
parentNode.NodeID = myRows[p]["KEY"].ToString();
root.Nodes.Add(parentNode);
}
else
{
foreach (Ext.Net.TreeNode nodo in root.Nodes)
{
if (nodo.NodeID == myRows[p]["FATHER"].ToString())
{
//Ext.Net.TreeNode nodo = root.Nodes[0];
Ext.Net.TreeNode childNode = new Ext.Net.TreeNode();
childNode.Text = myRows[p]["TITLE"].ToString();
childNode.NodeID = myRows[p]["KEY"].ToString();
nodo.Nodes.Add(childNode);
}
}
}
}
Ext.Net.Panel panel1 = new Ext.Net.Panel("Settings");
Ext.Net.Panel panel2 = new Ext.Net.Panel("Even More Stuff");
Ext.Net.Panel panel3 = new Ext.Net.Panel("My Stuff");
Ext.Net.Toolbar toolbar = new Ext.Net.Toolbar();
Ext.Net.Window window = new Ext.Net.Window();
window.Title = "Accordion Window";
window.Width = Unit.Pixel(250);
window.Height = Unit.Pixel(400);
window.Maximizable = true;
window.BodyBorder = false;
window.Layout = "Accordion";
window.TopBar.Add(toolbar);
window.Items.Add(tree);
window.Items.Add(panel1);
window.Items.Add(panel2);
window.Items.Add(panel3);
this.PlaceHolder3.Controls.Add(window);
}
}
Page .aspx
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="gm_usercs_Main" Title="Untitled Page" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!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>
<title>Ciao</title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager3" runat="server">
</ext:ResourceManager>
<asp:PlaceHolder ID="PlaceHolder3" runat="server" />
</form>
</body>
</html>
Screen: http://i.imgur.com/UtUrd.png
but it should be like this: http://i.imgur.com/pKlEv.png
So my code doesnt show sublevel... I hope to be clear... thanks for your patience ^^
-
If a node looks a leaf node, it means there is no children. Please ensure you add children to respective nodes.