Solved

How can I expand a treeview node programatically.

Posted on 2007-03-22
7
261 Views
Last Modified: 2010-08-05
If I have a node  aNode
How would I expand that node?

I thought aNode.Expand = true; but that give me an error.

C# only please.
0
Comment
Question by:Prysson
  • 3
  • 2
7 Comments
 
LVL 16

Accepted Solution

by:
AlexNek earned 500 total points
ID: 18770731
Did you try
aNode.Expand();?
           
           
0
 
LVL 2

Expert Comment

by:_Eyeball_
ID: 18770826
Yep! It's aNode.Expand()! Copy, paste and see :)

best regards

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            treeNode1 = new System.Windows.Forms.TreeNode("Knoten1");
            treeNode2 = new System.Windows.Forms.TreeNode("Knoten0", new System.Windows.Forms.TreeNode[] {
            treeNode1});
            this.treeView1 = new System.Windows.Forms.TreeView();
            this.SuspendLayout();
            //
            // treeView1
            //
            this.treeView1.Location = new System.Drawing.Point(54, 65);
            this.treeView1.Name = "treeView1";
            treeNode1.Name = "Knoten1";
            treeNode1.Text = "Knoten1";
            treeNode2.Name = "Knoten0";
            treeNode2.Text = "Knoten0";
            this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
            treeNode2});
            this.treeView1.Size = new System.Drawing.Size(121, 97);
            this.treeView1.TabIndex = 0;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 274);
            this.Controls.Add(this.treeView1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion
        private System.Windows.Forms.TreeNode treeNode1;
        private System.Windows.Forms.TreeNode treeNode2;
        private System.Windows.Forms.TreeView treeView1;

        public Form1()
        {
            InitializeComponent();
            treeNode2.Expand();
        }
    }
}
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 18771130
Congratulation!!
BTW I'm in Germany too.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Prysson
ID: 18771159
Thanks! I was missing the ().
0
 

Author Comment

by:Prysson
ID: 18771572
oops. Selected the wrong solution. I will submit to the admins to change this.
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 18771652
Not a big problem, I was wrong in second post, too. I thinking it was your working code.
In addition, you can use ExpandAll() too.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now