.NET4.0 / VS 2010
The treeView never populates past Jobs.
I have a SQL table with the following:
Node NodeName ParentNode
0 Jobs 0
1 Child1 0
2 Child2 1
3 Child3 1
4 Child4 3
5 Child5 4
6 Child6 4
private void FillTree()
{
con = new System.Data.SqlClient.SqlConnection();
dsl = new DataSet();
con.ConnectionString = "Data Source=Server;Initial Catalog=DB;Persist Security Info=True;User ID=Tester;Password=Pass";
string sql = "Select * from nodes";
dr = new System.Data.SqlClient.SqlDataAdapter(sql, con);
con.Open();
dr.Fill(dsl, "Nodes");
TreeNode Node0 = new TreeNode("Jobs");
TreeNode Root = new TreeNode("-->");
Root.Nodes.Add(Node0);
treeView1.Nodes.Add(Root);
foreach (DataRow theRow in dsl.Tables[0].Rows)
{
TreeNode nodeNum = new TreeNode(theRow["Node"].ToString());
TreeNode nodeName = new TreeNode(theRow["NodeName"].ToString());
TreeNode parentNode = new TreeNode("Node" + (theRow["ParentNode"].ToString()));
parentNode.Nodes.Add(nodeName);
}
}
I think it has something to do with the Root and Jobs being at Node0. I tried to do and conditional statement to skip the parentNode = "Node0" and NodeName = "Jobs" but for some reason it never sees the NodeName as "Jobs" in the conditional statement.
string parentCondition = ("Node" + (theRow["ParentNode"].ToString()));
string nodeCondition = (theRow["NodeName"].ToString());
if ((parentCondition.Equals("Node0")) & (nodeCondition.Equals("Jobs")))
{
}