Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
200
When i databind the tree to a business collection, the sub nodes won't be created correct
posted

when binding the tree to a collection like

  • root
    • child 1
    • child 2
      • child 2.1
        • child 2.1.1
      • child 2.2
        • child 2.2.1
      • child 2.3
        • child 2.3.1

child 2.1.1 -> 2.3.1 won't be visible

some sample code

Create a new project, add the following code and run.

Uncomment the row : // root.Children[0].Children.Add(new NodeItem("hide me and child 2.1.1 -> child 2.3.1 will be invisible"))

---- code:

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
using Infragistics.Win.UltraWinTree;

namespace BindTreeTest
{
    public class Form1 : Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private readonly IContainer components = null;

        private UltraTree ultraTree1;

        public Form1()
        {
            this.InitializeComponent();

            var root = new NodeItem("root");

            root.Children.Add(new NodeItem("child 1"));
            root.Children.Add(new NodeItem("child 2"));

            // if this node is hidden, the child 2.1.1 -> 2.1.3 nodes will not be visible
            // root.Children[0].Children.Add(new NodeItem("hide me and child 2.1.1 -> child 2.1.3 will be invisible"));

            root.Children[1].Children.Add(new NodeItem("child 2.1"));
            root.Children[1].Children.Add(new NodeItem("child 2.2"));
            root.Children[1].Children.Add(new NodeItem("child 2.3"));
            root.Children[1].Children[0].Children.Add(new NodeItem("child 2.1.1"));
            root.Children[1].Children[1].Children.Add(new NodeItem("child 2.2.1"));
            root.Children[1].Children[2].Children.Add(new NodeItem("child 2.3.1"));

            var collection = new ObservableCollection<NodeItem> {root};
            this.ultraTree1.DataSource = collection;

            this.ultraTree1.ExpandAll();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }


        private void ultraTree1_ColumnSetGenerated(object sender, ColumnSetGeneratedEventArgs e)
        {
            e.ColumnSet.NodeTextColumn = e.ColumnSet.Columns["Text"];
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            var _override1 = new Infragistics.Win.UltraWinTree.Override();
            this.ultraTree1 = new Infragistics.Win.UltraWinTree.UltraTree();
            ((System.ComponentModel.ISupportInitialize) (this.ultraTree1)).BeginInit();
            this.SuspendLayout();
            // 
            // ultraTree1
            // 
            this.ultraTree1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ultraTree1.Location = new System.Drawing.Point(0, 0);
            this.ultraTree1.Name = "ultraTree1";
            _override1.ShowExpansionIndicator = Infragistics.Win.UltraWinTree.ShowExpansionIndicator.CheckOnDisplay;
            this.ultraTree1.Override = _override1;
            this.ultraTree1.Size = new System.Drawing.Size(579, 432);
            this.ultraTree1.TabIndex = 0;
            this.ultraTree1.ViewStyle = Infragistics.Win.UltraWinTree.ViewStyle.Standard;
            this.ultraTree1.ColumnSetGenerated +=
                new Infragistics.Win.UltraWinTree.ColumnSetGeneratedEventHandler(this.ultraTree1_ColumnSetGenerated);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(579, 432);
            this.Controls.Add(this.ultraTree1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize) (this.ultraTree1)).EndInit();
            this.ResumeLayout(false);
        }

        #endregion

        #region Nested type: NodeItem

        public class NodeItem : NodeItemBase
        {
            public NodeItem(string text) : base(text)
            {
            }
        }

        #endregion

        #region Nested type: NodeItemBase

        public abstract class NodeItemBase
        {
            protected NodeItemBase(string text)
            {
                this.Children = new ObservableCollection<NodeItemBase>();
                this.Text = text;
            }

            public string Text { getset; }
            public ObservableCollection<NodeItemBase> Children { getprivate set; }
        }

        #endregion
    }
}

 

Parents
  • 200
    Offline posted

    Hi Mike,

    The ObservableCollection class is now standard in .NET 4.0

    I've uploaded a sample project, replaced the ObservableCollection to a BindingList and upgraded to the latest ServiceRelease. Still doesn't work.

     

     

    BindingTreeSample.zip
Reply Children