Saturday 15 May 2010

c# - windows form treeview with dynamic child -


I am working on a windows form in C # to create a treeview using data from a database, such as a .html

ID - Node ID Description - The value displayed in the tree view is ENDNode - 0 if it is the end node; 1 If the child of this node is

If I have 1, then I have to call the same shop process with the current node ID to get a list of hair nodes under it

< P> I have created a mechanism that will call the store process and get the list of items but I am not sure how to populate the tree structure. I was thinking that I will show the first list as parent nodes and when users click on the + icon on the extension, I will call the store process and add the new item to the current node as a child. I'm not sure how to tell the node that it's a parental node and not the end node. Has anyone made such a thing? Please help

I have created a sample for you, within which you can understand it

A table of employees was created in the database

Initially the name of the workers will be put in the tree wheel

When the name is expanded, then their age and phone Numbers can be seen.

  Public Form 1 () {InitializeComponent (); InitTreeView (); // TreeView in it without any nodes} zero initTreeView () {SqlConnection con = new SqlConnection (); Con.ConnectionString = _ConnectionString; Con.Open (); (Read.Read ()) using (SqlDataReader read = comm.ExecuteReader ()) (SqlCommand comm = new SqlCommand ("select name from employee")) {TreeNode tn = new TreeNode ( ["Name"] Read .tar ()); Tn.Nodes.Add (New TreeNode ()); TreeView1.Nodes.Add (Tamilnadu); } Tree View 1 After this Expand + = Tree View 1_BEforeExpand; } Void treeView1_BeforeExpand (object sender, treewuckensell event events e) {tree_node = e.Node; String empName = tNode.Text; TNode.Nodes.Clear (); SqlConnection con = new SqlConnection (); Con.ConnectionString = _ConnectionString; Con.Open (); (SqlCommand comm = new SqlCommand ("Select age, phone number to employee, where name = @empName", con)) {comm.Parameters.AddWithValue ("@ empName", empName); (Read.Read ()) {TreeNode NodeAge = New Treeode (Read "[" Age "]."); TreeNode Nodfone = New Tree Node (Read [ "Phone number"]. Click on tostring (); TNode.Nodes.AddRange (New Treeode [] {nodege, nodefone});}}}  

No comments:

Post a Comment