I am trying to create a multilevel tree view using ObjectListview. But problem is that it create only one parent and add the child in that parent. My tree stricture in any form
A
-a1
-a2
-a3
-a4
- a4(i)
B
- b (a)
- c (a)
C
Means my tree can be multilevel. Below is my code that i use to bind the treeListView
private void InitializeData(int appId)
{
try
{
UserDAC _UserDAC = new UserDAC();
DataTable SEC_InfoTreeView = _UserDAC.GetAPPITEMSbyAPPID(appId, "", this.FindForm().Name, "InitializeFristTabValue()").Tables[0];
data = new List<Node> { }; // this i bind my treelistview
var Blank = new Node(0, "User Name", "Status", "Static Caption");
var parent1= new Node(0,"", "", " ");
treeListView1.SmallImageList = imageList1;
if (SEC_InfoTreeView.Rows.Count > 0)
{
for (int i = 0; i < SEC_InfoTreeView.Rows.Count; i++)
{
if (i == 0)
data.Add(Blank);
int PrentID = Convert.ToInt32(SEC_InfoTreeView.Rows[i]["PARENTID"]);
if (Convert.ToString(SEC_InfoTreeView.Rows[i]["INDENT"]) != "")
{
if (PrentID == 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 0)
{
data.Add(parent1);
var parentAdd = new Node(Convert.ToInt32(SEC_InfoTreeView.Rows[i]["APPITEMID"]), Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]), "", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"]));
parent1 = parentAdd;
}
else if (PrentID != 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 2)
{
parent1.Children.Add(new Node(Convert.ToInt32(SEC_InfoTreeView.Rows[i]["APPITEMID"]),Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]), "", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"])));
}
else if (PrentID != 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 4)
{
parent1.Children.Add(new Node(Convert.ToInt32(SEC_InfoTreeView.Rows[i]["APPITEMID"]),Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]), "", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"])));
}
else if (PrentID != 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 6)
{
parent1.Children.Add(new Node(Convert.ToInt32(SEC_InfoTreeView.Rows[i]["APPITEMID"]),Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]),"", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"])));
}
else if (PrentID != 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 10)
{
parent1.Children.Add(new Node(Convert.ToInt32(SEC_InfoTreeView.Rows[i]["APPITEMID"]),Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]), "", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"])));
}
else if (PrentID != 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 8)
{
parent1.Children.Add(new Node(Convert.ToInt32(SEC_InfoTreeView.Rows[i]["APPITEMID"]),Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]),"", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"])));
}
else if (PrentID != 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 12)
{
parent1.Children.Add(new Node(Convert.ToInt32(SEC_InfoTreeView.Rows[i]["APPITEMID"]),Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]), "", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"])));
}
else if (PrentID != 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 14)
{
parent1.Children.Add(new Node(Convert.ToInt32(SEC_InfoTreeView.Rows[i]["APPITEMID"]),Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]), "", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"])));
}
else if (PrentID != 0 && Convert.ToInt32(SEC_InfoTreeView.Rows[i]["INDENT"]) == 16)
{
parent1.Children.Add(new Node(Convert.ToInt32(SEC_InfoTreeView.Rows[i]["APPITEMID"]),Convert.ToString(SEC_InfoTreeView.Rows[i]["USERNAME"]), "", Convert.ToString(SEC_InfoTreeView.Rows[i]["ACAPTION"])));
}
}
}
}
}
catch (Exception ex)
{
}
}
class Node
{
public int Id { get; private set; }
public string Name { get; private set; }
public string Column1 { get; private set; }
public string Column2 { get; private set; }
public List<Node> Children { get; private set; }
public Node(int id, string name, string col1, string col2)
{
this.Id = id;
this.Name = name;
this.Column1 = col1;
this.Column2 = col2;
this.Children = new List<Node>();
}
}
And for bind the treeview i use this code this.treeListView1.Roots = data;
Almost i try this from last 21 hrs but not get the correct treeview structure . Very thanks for your help .