TreeView Control
TreeView Control is used for showing hierarchical structured data visually e.g.. XML.Example for TreeView Control In shown Below -This is image of Explorer in Windows that show files and folder in tree view.
Working With TreeView Control
Drag and drop TreeView Control from toolbox, Like shown in below image.
Code for Add Child is given Below
private void buttonAddChild_Click(object sender, System.EventArgs e)
{
if (textBox1.Text != "")
AddChildToTheNode();
else
{
MessageBox.Show("Enter the Node Text to be added");
textBox1.Focus();
}
}
|
private void menuItem2_Click(object sender, System.EventArgs e)
{
if (textBox1.Text != "")
AddChildToTheNode();
else
{
MessageBox.Show("Enter the Node Text to be added");
textBox1.Focus();
}
} |
private void btnAddSibling_Click(object sender, System.EventArgs e)
{
if (textBox1.Text != "")
AddSiblingToTheNode();
else
{
MessageBox.Show("Enter the Node Text to be added");
textBox1.Focus();
}
}
|
Code For Deleting Child and Sibling.
private void buttonDeleteParent_Click(object sender, System.EventArgs e)
{
DeleteNode();
}
private void DeleteNode()
{
if (treeView1.SelectedNode.Nodes.Count == 0)
treeView1.SelectedNode.Remove();
else
MessageBox.Show("First Remove all the child nodes");
} |
Working with TreeView in C#.NET
ReplyDelete