C#TreeViewAdv获取所选节点的值

时间:2017-08-18 08:03:40

标签: c# winforms treeview

我在多列模式下使用syncfusion的TreeViewAdv。

我正在尝试获取所选节点的值(来自第一列),但我没有成功。

有没有人能够做到这一点?

非常感谢

编辑:

快速更新我如何填充控件

    private void RefreshOptions()
    {
        List<String> objects = Globals.ThisAddIn.utilities.ListRObjectsWithDetail();
        StringBuilder name = new StringBuilder(100);
        StringBuilder details = new StringBuilder(200);
        Node dataRootNode = new Node();
        Node dataParentNode = new Node();
        Node dataChildNode1 = new Node();
        Node dataChildNode2 = new Node();
        Node dataChildNode3 = new Node();
        Node functionsRootNode = new Node();
        Node functionsParentNode = new Node();
        int charLocation;
        int indexChild;
        int childLevel;
        TreeModel _model = new TreeModel();
        treeViewAdv1.Model = _model;
        treeViewAdv1.BeginUpdate();

        dataRootNode = new ColumnNode("Data / Values", "", "");
        _model.Nodes.Add(dataRootNode);

        functionsRootNode = new ColumnNode("Functions", "", "");
        _model.Nodes.Add(functionsRootNode);

        foreach (String obj in objects)
        {
            name.Clear();
            details.Clear();
            name.Append(obj.Trim());
            charLocation = name.ToString().IndexOf(":");
            details.Append(name.ToString().Substring(charLocation + 1).Trim());
            name.Length = charLocation;

            if (details.Length >=10 && details.ToString(0, 10) == "function (")
            {
                functionsParentNode = new ColumnNode(name.ToString(), "Function", details.ToString());
                functionsRootNode.Nodes.Add(functionsParentNode);
            }
            else
            {
                indexChild = name.ToString().IndexOf("$");
                if (indexChild > -1)
                {
                    childLevel = name.ToString(0, indexChild).Split('.').Length - 1;
                    name.Remove(0, 1 + childLevel);

                    switch (indexChild)
                    {
                        case 1:
                            dataChildNode1 = new ColumnNode(name.ToString(), "Data / Value", details.ToString());
                            dataParentNode.Nodes.Add(dataChildNode1);
                            break;
                        case 2:
                            dataChildNode2 = new ColumnNode(name.ToString(), "Data / Value", details.ToString());
                            dataChildNode1.Nodes.Add(dataChildNode2);
                            break;
                        case 3:
                            dataChildNode3 = new ColumnNode(name.ToString(), "Data / Value", details.ToString());
                            dataChildNode2.Nodes.Add(dataChildNode3);
                            break;
                    }
                }
                else
                {
                    dataParentNode = new ColumnNode(name.ToString(), "Data / Value", details.ToString());
                    dataRootNode.Nodes.Add(dataParentNode);
                }

            }
        }
        NodeTextBox ntb = new NodeTextBox();
        ntb.DataPropertyName = "Text";
        this.treeViewAdv1.NodeControls.Add(ntb);
        treeViewAdv1.EndUpdate();
    }

我花了一些时间查看TreeViewAdv示例项目。具体来说,我查看了具有以下NodeMouseDoubleClick事件的“FolderBrowser.cs”winform。这正确地将节点写入了控制台。

        private void _treeView_NodeMouseDoubleClick(object sender, TreeNodeAdvMouseEventArgs e)
    {
        Console.WriteLine(e.Node);
    }

如果我使用完全相同的事件,那么我的e.Node =“”虽然我的节点已完全填充。

0 个答案:

没有答案