Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to make tree node (Expand, Expand All, count, toggle, remove) using “Tree Node class” in VB and C# (.net 2.0). Part 5

Author: Zunnair
Download Source Code : 896_Tree Node.zip

In this simple article you will learn that how we can make a tree node and use of functions using “Tree Node class” in VB and C# .net 2.0.

 

To understand this article more read the part1, part2, part3 and part4 of this article.
Expand Node:
If you want to expand a particular node for this purpose tree node class has a function named expand (). This function takes and returns nothing. This function only expands the node, not expand its child.
To demonstrate make a window application drag a button and tree view control. Add the nodes.
Now write the following code on button click event:
C#
private void btn_Expand_Click(object sender, EventArgs e)
        {
            obj.Expand();
        }
VB
Private Sub btn_Expand_Click(ByVal sender As Object, ByVal e As EventArgs)
    obj.Expand()
End Sub
This simple code expands a node.
Expand All:
If you want to expand a particular node but also its child for this purpose tree node class has a function named expand all (). This function takes and returns nothing. This function expands the node and its child.
To demonstrate make a window application drag a button and tree view control. Add the nodes.
Now write the following code on button click event:
C#
private void btn_Expand_Click(object sender, EventArgs e)
        {
            obj.ExpandAll();
        }
VB
Private Sub btn_Expand_Click(ByVal sender As Object, ByVal e As EventArgs)
    obj.ExpandAll()
End Sub
This simple code expands the node and its child.
Count Child:
If you want to count the number of child of a particular node for this purpose tree node class provides us a function named Get Node Count (). This function takes a Boolean value which decides that the sub tree should be added during counting or not. True means add else not add. This function returns the integer which shows the number of child.
To demonstrate make a window application drag a button and tree view control. Add the nodes.
Now write the following code on button click event:
C#
private void btn_Count_Click(object sender, EventArgs e)
        {
            int i;
            bool b;
            b = false;
            i = obj.GetNodeCount(b);
            string str;
            str=i.ToString();
            MessageBox.Show(str);
        }
VB
Private Sub btn_Count_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim i As Integer
        Dim b As Boolean
        b = False
        i = obj.GetNodeCount(b)
        Dim str As String
        str = i.ToString()
        MessageBox.Show(str)
    End Sub
This simple code counts the number of child.
 
 
RemoveNode:
If you want to remove a particular node for this purpose tree node class provides us a function named remove (). This function takes and returns nothing and removes the node from tree view control.
To demonstrate make a window application drag a button and tree view control. Add the nodes.
Now write the following code on button click event:
C#
private void btn_Remove_Click(object sender, EventArgs e)
        {
            obj.Remove();
            MessageBox.Show("Node Removed");
        }
VB
Private Sub btn_Remove_Click(ByVal sender As Object, ByVal e As EventArgs)
        obj.Remove()
        MessageBox.Show("Node Removed")
    End Sub
This simple code removes the node from tree view.
Toggle:
If you want to toggle a particular node for this purpose tree node class provides us a function named Toggle (). This function takes and returns nothing. This function toggles the node, either collapse or expand state.
To demonstrate make a window application drag a button and tree view control. Add the nodes.
Now write the following code on button click event:
C#
private void btn_toggle_Click(object sender, EventArgs e)
        {
            obj.Toggle();
        }
VB
Private Sub btn_toggle_Click(ByVal sender As Object, ByVal e As EventArgs)
        obj.Toggle()
    End Sub
This simple code toggles the node.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "DEVASP TREE NODE APPLICATION";
        }     
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Me.Text = "DEVASP TREE NODE APPLICATION"
    End Sub
 
This simple article tells that how we can make a tree node and set node properties using “Tree Node class” in VB and C# .net 2.0.
   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to make tree node (Previous Visible Node, Begin edit, stop edit, collapse) using “Tree Node class” in VB and C# (.net 2.0). Part 4

Disclaimer - Privacy
© 2002-2017 DevASP.net