Sponsored Ad

Tuesday, September 29, 2009

C# TreeView

This article addressing some of the basics of working with a TreeView control; the commodity will abode dynamically abacus TreeNodes to a TreeView control, earching the nodes to find and highlight a single node or a collection of nodes matching a search term against the TreeNode's tag, text, or name properties, and manually or programmatically selecting nodes.

The application solution contains a single Windows Application project comprised;all cipher supplied in abutment of this activity is independent in two anatomy classes; one is the capital anatomy absolute the TreeView and a few controls acclimated to affectation bulge advice nd to execute searches for a specific node or group of nodes based upon a user supplied search term. The other form class is used to create new nodes; within the application, this form is displayed by selecting a node from the TreeView and then selecting the "Add Node" option from the context menu.

The functionality contained in the class is broken up into several regions; the class begins with the default imports, namespace declaration, and class declaration:

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace EasyTreeView

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

            // start off by adding a base treeview node

            TreeNode mainNode = new TreeNode();

            mainNode.Name = "mainNode";

            mainNode.Text = "Main";

            this.treeView1.Nodes.Add(mainNode);

        }

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers