.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Using a TreeView

Posted By:Shashi Ray       Posted Date: February 25, 2009    Points: 25    Category: C#    URL: http://www.dotnetspark.com  
 

Using a TreeView

 

If, however, you choose to use a TreeView control to display the data you select, you will find that there is no convenient interface that you can use to keep your code from changing. For each node you want to create, you create an instance of the TreeNode class and add the root TreeNode collection to another node. In our example version using the TreeView, we'll add the swimmer's name to the root node collection and the swimmer's time as a subsidiary node.

Here is the entire TreeAdapter class.

 

public class TreeAdapter:LstAdapter {

private TreeView tree;

//------

public TreeAdapter(TreeView tr) {

tree=tr;

}

//------

public void Add(Swimmer sw) {

TreeNode nod;

//add a root node

nod = tree.Nodes.Add(sw.getName());

//add a child node to it

nod.Nodes.Add(sw.getTime().ToString ());

tree.ExpandAll ();

}

//------

public int SelectedIndex() {

return tree.SelectedNode.Index ;

}

//------

public void Clear() {

TreeNode nod;

for (int i=0; i< tree.Nodes.Count ; i++) {

nod = tree.Nodes [i];

nod.Remove ();

}

}

//------

public void clearSelection() {}

}

 

Shashi Ray


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend