Click here to Skip to main content
15,887,416 members
Home / Discussions / C#
   

C#

 
GeneralRe: Prevent same user to login Pin
Xmen Real 1-Aug-09 18:05
professional Xmen Real 1-Aug-09 18:05 
QuestionSingleton Pattern - When Use Pin
dataminers1-Aug-09 8:15
dataminers1-Aug-09 8:15 
AnswerRe: Singleton Pattern - When Use Pin
Not Active1-Aug-09 9:12
mentorNot Active1-Aug-09 9:12 
GeneralRe: Singleton Pattern - When Use Pin
dataminers1-Aug-09 10:14
dataminers1-Aug-09 10:14 
QuestionTreeView Recursion Pin
Muammar©1-Aug-09 7:50
Muammar©1-Aug-09 7:50 
AnswerRe: TreeView Recursion Pin
Mike Ellison1-Aug-09 10:47
Mike Ellison1-Aug-09 10:47 
GeneralRe: TreeView Recursion Pin
Muammar©1-Aug-09 12:50
Muammar©1-Aug-09 12:50 
GeneralRe: TreeView Recursion Pin
OriginalGriff1-Aug-09 21:59
mveOriginalGriff1-Aug-09 21:59 
Here's the method I use:
/// <summary>
/// Adds a branch to a TreeView control
/// </summary>
/// <remarks>
/// The Path contains the name of the node to be used in the tree view, for example
/// "General" or "Colours".
/// If the path is qualified with '\' or '/' then it is treated as a hierarchical path
/// and the full path required is generated. For example, if the path was
/// "General\Colors\Pens" the the tree view would display
///      General
///          Colours
///              Pens
/// and any of these branches would select the node.
///
/// The Description can be used for the display of more information.
/// </remarks>
/// <example>
/// AddBranch(tvSelect.Nodes,
///           @"General\Colours",
///           @"Change the colours settings for items",
///           object o);
/// </example>
/// <param name="nc">TreeNodeCollection: TreeView Nodes collection to add to</param>
/// <param name="Path">string: TreeView Hierarchy path to object</param>
/// <param name="Description">string: Plain english description of the object</param>
/// <param name="o">object: object to add to TreeView</param>
public static void AddBranch(TreeNodeCollection nc, string Path, string Description, object o)
    {
    string[] paths = Path.Split('\\', '/'); // Break "General\Font" to "General", "Font" etc.
    TreeNode node;
    foreach (string s in paths)
        {
        if (s == null || s == "")
            {
            // Ignore leading "\", or instances of "\\".
            continue;
            }
        if ((node = FindBranch(nc, s)) == null)
            {
            // Branch does not exist.
            // create it.
            node = new TreeNode();
            node.Name = Description;
            node.Text = s;
            node.Tag = o;
            nc.Add(node);
            }
        // Move down the tree.
        // This allows us to create the sub-branches.
        nc = node.Nodes;
        }
    }

/// <summary>
/// Locates a given Node, returns it if found
/// </summary>
/// <param name="nc">TreeNodeCollection: List of TreeNode items to search</param>
/// <param name="name">string: Name of branch (or leaf) to search for.</param>
/// <returns>Node if found, null if not.</returns>
public static TreeNode FindBranch(TreeNodeCollection nc, string name)
    {
    if ((name != null) && (name != ""))
        {
        foreach (TreeNode n in nc)
            {
            if (n.Text == name)
                {
                return n;
                }
            }
        }
    return null;
    }


Comments make it pretty obvious how to use.

No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.

This message is made of fully recyclable Zeros and Ones

GeneralRe: TreeView Recursion Pin
Muammar©1-Aug-09 23:18
Muammar©1-Aug-09 23:18 
GeneralRe: TreeView Recursion Pin
OriginalGriff2-Aug-09 0:34
mveOriginalGriff2-Aug-09 0:34 
GeneralRe: TreeView Recursion Pin
Muammar©2-Aug-09 1:01
Muammar©2-Aug-09 1:01 
AnswerRe: TreeView Recursion Pin
N a v a n e e t h9-Aug-09 4:47
N a v a n e e t h9-Aug-09 4:47 
GeneralRe: TreeView Recursion Pin
Muammar©9-Aug-09 9:53
Muammar©9-Aug-09 9:53 
GeneralRe: TreeView Recursion Pin
N a v a n e e t h9-Aug-09 16:31
N a v a n e e t h9-Aug-09 16:31 
GeneralRe: TreeView Recursion Pin
Muammar©10-Aug-09 2:19
Muammar©10-Aug-09 2:19 
GeneralRe: TreeView Recursion Pin
N a v a n e e t h10-Aug-09 7:40
N a v a n e e t h10-Aug-09 7:40 
GeneralRe: TreeView Recursion Pin
Muammar©10-Aug-09 7:49
Muammar©10-Aug-09 7:49 
GeneralRe: TreeView Recursion Pin
Muammar©10-Aug-09 8:04
Muammar©10-Aug-09 8:04 
GeneralRe: TreeView Recursion Pin
Muammar©10-Aug-09 8:14
Muammar©10-Aug-09 8:14 
GeneralSolved:) Pin
Muammar©10-Aug-09 8:21
Muammar©10-Aug-09 8:21 
GeneralA minor bug?? I hope :s [modified] Pin
Muammar©10-Aug-09 8:35
Muammar©10-Aug-09 8:35 
GeneralRe: A minor bug?? I hope :s Pin
N a v a n e e t h10-Aug-09 9:29
N a v a n e e t h10-Aug-09 9:29 
GeneralRe: A minor bug?? I hope :s Pin
Muammar©10-Aug-09 10:21
Muammar©10-Aug-09 10:21 
GeneralRe: TreeView Recursion [modified] Pin
Muammar©10-Aug-09 7:45
Muammar©10-Aug-09 7:45 
General[Message Deleted] Pin
Muammar©11-Aug-09 3:13
Muammar©11-Aug-09 3:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.