Click here to Skip to main content
15,916,379 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I create 1 application.in that i ave to use treeview.
Such as;

1.Node
a. Node1
b. Node2
2.Type
a. Int
b. Bool
3.Size
a. 1
b. 2

In above example Node,Type,size are parent node.So i want the index of these paren node as well as also want for child node also.Suppose I select Node-->node1 then initailly after selecting i get list of names related to it.Now i select Type-->int that i i don't understand how to compare it.bydefault i get all name related to Node-->node1.I just want index of parent and child node.remainind disply part i done it.
Posted

1 solution

Just try this....

SQL
int a = treeView1.SelectedNode.Parent.Index;
int b = treeView1.SelectedNode.FirstNode.Index;


Regards
Sebastian
 
Share this answer
 
Comments
Member 8131879[Sneha K] 30-May-12 6:11am    
Hello,

I solved the problem which i mentioned above.

Now want to ask another one is that,i want list of all parent node and child node.

example: I have total 4 parent node as;

All ....parent node

ID ....parent node

1 ..child node

2 ..child node

Name ....parent node

abc ..child node

xyz ..child node

Address ....parent node

123 ..child node

124 ..child node

my question is that, i) i want list of all parent and child nodes.

ii) Also ,When i select or check option all then automatically other parent and child node

get select.

iii) Also,when i select particular node that time title of this node shoulg get bold.For it i get solution as;

private void CheckAllChildNodes(TreeNode treeNode, bool nodeChecked)
{
TreeNode oMainNode = oYourTreeView.Nodes[0];
PrintNodesRecursive(oMainNode);

int x = treeView1.SelectedNode.Index;
Font boldFont = new Font(treeView1.Font, FontStyle.Bold);



foreach (TreeNode node in treeNode.Nodes)
{
node.Checked = nodeChecked;
if (node.Nodes.Count >= 0)
{

this.CheckAllChildNodes(node, nodeChecked);


}


treeView1.Nodes[s].NodeFont = new Font(treeView1.Font, FontStyle.Bold);

private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
if (e.Action != TreeViewAction.Unknown)
{
if (e.Node.Nodes.Count > 0)
{
/* Calls the CheckAllChildNodes method, passing in the current
Checked value of the TreeNode whose checked state changed. */
// s = e.Node.ToString();
s= e.Node.Index;
this.CheckAllChildNodes(e.Node, e.Node.Checked);
}
}

}

By using it i get bold letter for parent node.but,for first parent node "All" above code not applicable.I checked the index for it.but only for 1st option title of node not get bold.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900