• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 49
  • Last Modified:

treeview node visible

Hİ;

I want to treeview node visible (form load) for c# but i don't know please help me.
0
Gökmen Anıl Yılmaz
Asked:
Gökmen Anıl Yılmaz
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
Nitin SontakkeDeveloperCommented:
Please share whatever code you got already. Whatever mentioned is just an opinion and very abstract to comment on.
0
 
Gökmen Anıl YılmazStudentAuthor Commented:
I want any TreeView nodes to be invisible when the form is loaded
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Actually at the form load the form itself is not visible.  You need to explain more clearly what you want / what you have done that doesn't work.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Gökmen Anıl YılmazStudentAuthor Commented:
for example ;

if login is admin ,  Form2.node will see, if login not admin Form2.node doesnt see?
0
 
MishaProgrammerCommented:
There is a property "visible" from each node of treeView. But this property is read only.
If you want to make invisible one node (not all treView), you can inherit from tree node and create your own behaviour.

public class RootNode : TreeNode
{
    public List<ChildNode> ChildNodes { get; set; }

    public RootNode()
    {
        ChildNodes = new List<ChildNode>();
    }

    public void PopulateChildren()
    {
        this.Nodes.Clear();

        var visibleNodes = 
            ChildNodes
            .Where(x => x.Visible)
            .ToArray();

        this.Nodes.AddRange(visibleNodes);
    }

    //you would use this instead of (Nodes.Add)
    public void AddNode(ChildNode node)
    {
        if (!ChildNodes.Contains(node))
        {
            node.ParentNode = this;
            ChildNodes.Add(node);
            PopulateChildren();
        }
    }

    //you would use this instead of (Nodes.Remove)
    public void RemoveNode(ChildNode node)
    {
        if (ChildNodes.Contains(node))
        {
            node.ParentNode = null;
            ChildNodes.Remove(node);
            PopulateChildren();
        }

    }
}

public class ChildNode : TreeNode
{
    public RootNode ParentNode { get; set; }
    private bool visible;
    public bool Visible { get { return visible; } set { visible = value;OnVisibleChanged(): } }
    private void OnVisibleChanged()
    {
        if (ParentNode != null)
        {
            ParentNode.PopulateChildren();
        }
    }
}

Open in new window

0
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>if login is admin ,  Form2.node will see, if login not admin Form2.node doesnt see?

If login is not admin - do not add Form2.node to the treeview when filling the data
0
 
MishaProgrammerCommented:
There is no activity from author
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now