insertNewChild() doesn't display anything

I’m trying to get the nodes using depth. I’m getting all the values from a database and the values are all unique and correct. So, when I’m at the very first node, i.e. when depth is 0, the nodes are being displayed correctly but when I try to start from any other node, there is nothing being displayed. I tried alerting the insertNewchild to see what value it is getting. When it is at the first node, it alerts object object but at any other node it alerts -1. When I debug the code, all the other values are being taken in correctly. Please help me.

function populateTree(xml)
{
var xmlDoc = parseXMLText(xml);
var root = xmlDoc.documentElement;
var userTree = new Array();
if(root.nodeName == ‘AdvertisementTree’)
{
userTree = xmlListToArray(root, ‘id’);
}
var treeNodesCount = userTree.length;
tree.deleteChildItems(0);
for(var i = 0; i < treeNodesCount; i++)
{
var treeNode = userTree[i];
var type = treeNode[‘Type’];
if(type === ‘group’)
{
var id = parseInt(treeNode[‘id’], 10);
if(id > maxID)
maxID = id;
alert(tree.insertNewChild(treeNode[‘ParentID’], id, treeNode[‘Name’], 0, ‘folderClosed.gif’));
tree.setUserData(id, ‘nodename’, treeNode[‘Name’]);
tree.setUserData(id, ‘type’, type);
}
else if(type === ‘advertisement’)
{
var id = parseInt(treeNode[‘id’], 10);
if(id > maxID)
maxID = id;
tree.insertNewChild(treeNode[‘ParentID’], id, treeNode[‘Name’], 0, ‘advertisement.png’);
tree.setUserData(id, ‘nodename’, treeNode[‘Name’]);
tree.setUserData(id, ‘type’, type);
tree.setUserData(id, ‘playlistid’, treeNode[‘PlaylistID’]);
}
}
}

The code below works when I give 0 for parentID but everyting appears in the same column. It’s not like a child node and parent node.

Hi,

here is the example of building tree via insertNewChild:

myTree = new dhtmlXTreeObject("treeDiv","100%","100%",0); myTree.setImagePath("../../codebase/imgs/dhxtree_skyblue/"); myTree.insertNewChild(0,1,"Item 1"); myTree.insertNewChild(1,11,"Child 1-1"); myTree.insertNewChild(1,12,"Child 1-2"); myTree.insertNewChild(1,13,"Child 1-3");