当前位置: 首页>>代码示例>>C#>>正文


C# TreeNode.AddChild方法代码示例

本文整理汇总了C#中System.Windows.Forms.TreeNode.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNode.AddChild方法的具体用法?C# TreeNode.AddChild怎么用?C# TreeNode.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.TreeNode的用法示例。


在下文中一共展示了TreeNode.AddChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Form1_Load

        // Build and display a tree.
        private void Form1_Load(object sender, EventArgs e)
        {
            // Build the tree.
            TreeNode president = new TreeNode("President");
            TreeNode sales = president.AddChild("VP Sales");
            sales.AddChild("Domestic Sales");
            sales.AddChild("International Sales");
            sales.AddChild("Sales Partners");
            TreeNode production = president.AddChild("VP Production");
            production.AddChild("CA Plant");
            production.AddChild("HI Plant");
            production.AddChild("NY Plant");
            production.AddChild("Overseas Production");
            TreeNode marketing = president.AddChild("VP Marketing");
            marketing.AddChild("Television");
            marketing.AddChild("Print Media");
            marketing.AddChild("Electronic Marketing");

            // Display the tree.
            string text = "";
            IEnumerator<TreeNode> enumerator = president.GetEnumerator();
            while (enumerator.MoveNext())
                text += new string(' ', 4 * enumerator.Current.Depth) +
                    enumerator.Current.Text +
                    Environment.NewLine;
            text = text.Substring(0, text.Length - Environment.NewLine.Length);
            treeTextBox.Text = text;
            treeTextBox.Select(0, 0);
        }
开发者ID:vikramadhav,项目名称:Certification_70-483,代码行数:30,代码来源:Form1.cs

示例2: FillData

        // This will populate a subtree of nodes with additional nodes for each enumerable
        //  field/property of the object stored in the current subtree's root [current].
        private static void FillData(TreeNode current)
        {
            var data = current.Tag;

            if (data is string || data is int || data is bool)
            {
                return;
            }

            if (data is IEnumerable &&
                    !(data is String))
            {
                if (data is IDictionary)
                    foreach (var item in ((IDictionary)data).Keys)
                    {
                        current.AddChild(item.ToString(), ((IDictionary)data)[item]);
                    }
                else
                {
                    IList list = ((IEnumerable)data).EnumToArray();
                    for (int i = 0; i < list.Count; i++)
                    {
                        current.AddChild(list[i].GetType().Name, list[i]);
                    }
                }
                return;
            }

            // Run once through for fields...
            var fields = data.GetType().GetFields(DefaultBF);
            foreach (var info in fields)
            {
                var each = info.GetValue(data);
                TreeNode node = new TreeNode(info.Name);
                node.Tag = each;

                if (each is IEnumerable &&
                    !(each is String))
                {
                    if (each is IDictionary)
                        foreach (var item in ((IDictionary)each).Keys)
                        {
                            node.AddChild(item.ToString(), ((IDictionary)each)[item]);
                        }
                    else
                        foreach (var item in (IEnumerable)each)
                        {
                            node.AddChild(item.GetType().Name, item);
                        }
                }
                if (each is string || each is int || each is bool)
                    continue;
                current.AddChild(node);
            }

            // ... and once through for properties.
            var props = data.GetType().GetProperties(DefaultBF);
            foreach (var info in props)
            {
                var para = info.GetIndexParameters();
                object[] arr;
                if (para.Length == 0)
                    arr = null;
                else
                {
                    arr = new object[para.Length];
                    for (int p = 0; p < para.Length; p++)
                        arr[p] = null;
                }
                var each = info.GetValue(data, arr);
                TreeNode node = new TreeNode(info.Name);
                node.Tag = each;

                if (each is IEnumerable &&
                    !(each is String))
                {
                    if (each is IDictionary)
                        foreach (var item in ((IDictionary)each).Keys)
                        {
                            node.AddChild(item.ToString(), ((IDictionary)each)[item]);
                        }
                    else
                        foreach (var item in (IEnumerable)each)
                    {
                        node.AddChild(item.GetType().Name, item);
                    }
                }
                if (each is string || each is int || each is bool)
                    continue;
                current.AddChild(node);
            }

            // repeat for the child objects
            foreach (TreeNode node in current.Nodes)
            {
                foreach (TreeNode subNode in node.Nodes)
                {
                    FillData(subNode);
//.........这里部分代码省略.........
开发者ID:virmitio,项目名称:Temp2,代码行数:101,代码来源:Editor.cs

示例3: openToolStripMenuItem_Click

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ConfigTree.Nodes.Count > 0)
            {
                var ans = EditorUtil.ConfirmPrompt("Save before closing existing work?");
                if (ans == true)
                {
                    saveToolStripMenuItem_Click(sender, e);
                }
                if (ans == null)
                {
                    return;
                }
            }

            ConfigTree.Nodes.Clear();

            string loc = String.Empty;
            var regKey = Registry.LocalMachine.OpenSubKey(@"Software\CoApp\AutoBuild Service");
            if (regKey == null)
                loc = @"C:\AutoBuild";
            else
                loc = Path.GetDirectoryName((string) (regKey.GetValue("ConfigFile", @"C:\AutoBuild\config.conf")));

            var OFD = new OpenFileDialog();
            OFD.InitialDirectory = loc;
            OFD.Filter = @"AutoBuild Config files|config.conf|All Files (*.*)|*.*";
            OFD.FilterIndex = 1;
            OFD.RestoreDirectory = true;

            if (OFD.ShowDialog() != DialogResult.OK)
                return;

            try
            {
                if (!File.Exists(OFD.FileName))
                {
                    throw new FileNotFoundException("Unable to open specified file.", OFD.FileName);
                }
                TreeNode root = new TreeNode(RootNodeName);
                root.Tag = OFD.FileName;
                ConfigTree.Nodes.Add(root);

                // open file, produce and attach subnodes to root node for file
                UrlEncodedMessage UEM = new UrlEncodedMessage(File.ReadAllText(OFD.FileName),
                                                              AutoBuild.SerialSeperator, true);

                TreeNode top;

                if (UEM[".$T$"].Contains("AutoBuild_config"))
                {
                    var input = UEM.DeserializeTo<AutoBuild_config>();
                    top = new TreeNode(input.GetType().Name);
                    top.Tag = input;
                }
                else if (UEM[".$T$"].Contains("ProjectData"))
                {
                    var input = UEM.DeserializeTo<ProjectData>();
                    top = new TreeNode(input.GetType().Name);
                    top.Tag = input;
                }
                else
                {
                    Type type = Type.GetType(UEM[".$T$"]);
                    var obj = Activator.CreateInstance(type, true);
                    var input = UEM.DeserializeTo(obj);
                    top = new TreeNode(input.GetType().Name);
                    top.Tag = input;
                }

                root.AddChild(top);
                FillData(top);
            }
            catch (Exception E)
            {
                MessageBox.Show("Unable to open file.\n\n" + E.Message);
            }
        }
开发者ID:virmitio,项目名称:Temp2,代码行数:78,代码来源:Editor.cs


注:本文中的System.Windows.Forms.TreeNode.AddChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。