I have created a treeview in my project but problem while cliking on nodes then all nodes coming to show again to below of tree.
Loading
I have created a treeview in my project but problem while cliking on nodes then all nodes coming to show again to below of tree.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Srinivasan RamamoorthiRank #877 · 2.5K reputationPosted Oct 29, 2021, 9:51 AM EDT
You have to call populate treeview outside of if else condition and inside for loop.
Refer below code
private void PopulateTreeView(int parentId, TreeNode parentNode)
{
TreeNode childNode;
foreach (DataRow dr in _acountsTb.Select("[parent]=" + parentId))
{
TreeNode t = new TreeNode();
t.Text = dr["code"].ToString() + " - " + dr["ac_name"].ToString();
t.Name = dr["code"].ToString();
t.Tag = _acountsTb.Rows.IndexOf(dr);
if (parentNode == null)
{
treeView1.Nodes.Add(t);
childNode = t;
}
else
{
parentNode.Nodes.Add(t);
childNode = t;
}
PopulateTreeView(Convert.ToInt32(dr["code"].ToString()), childNode);
}
}
Vikas PanwarRank #1,447 · 1.1K reputationPosted Oct 29, 2021, 4:52 AM EDT
Srinivasan RamamoorthiRank #877 · 2.5K reputationPosted Oct 29, 2021, 6:43 AM EDT
sanjeev roy191 reputationPosted Oct 29, 2021, 9:11 AM EDT
Ramamoorthi, I had check with this code but not solved even i had tried by some other , still showing same .
Srinivasan RamamoorthiRank #877 · 2.5K reputationPosted Oct 29, 2021, 9:19 AM EDT
sanjeev roy191 reputationPosted Oct 29, 2021, 9:25 AM EDT
sanjeev roy191 reputationPosted Oct 29, 2021, 1:50 PM EDT
Vikas PanwarRank #1,447 · 1.1K reputationPosted Oct 29, 2021, 4:52 AM EDT