Treeview - 节点不扩展 [英] Treeview - node not expanding

查看:97
本文介绍了Treeview - 节点不扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个节点的TreeView,如果删除了一个特殊节点(您将在代码中看到),则应在更新TreeView后扩展父节点。



我仍​​然需要帮助:(



我尝试过:



I have a TreeView with several nodes and if a special node (you will see in code) is deleted, the parent node should be expanded after updating the TreeView.

I still need help :(

What I have tried:

public void Remove(){
    ...
    ...
    else if ((NodeType)n.Tag == NodeType.Attribute) //Here I simply check if it's the "special" parent
    {
       Commands.CommandAttributeRemove cmd = (Commands.CommandAttributeRemove)mAppData.CommandFactory.Create("AttributeRemove");
       cmd.Data = n.Text;
       cmd.ObjectClass = mObjectClass;
       cmd.ObjectTypeName = n.Parent.Parent.Text;
       list.Add(cmd);
       mNodeToExpand = mTreeView.SelectedNode.Parent; //THIS LINE IS IMPORTANT... mNodeToExpand is a member variable which I use in UpdateData()
    }
    ...
    ...
    UpdateData();
}

public void UpdateData()
    {
       … //A lot of not so important stuff happening here (at least not important for what I want, I think)
       ...
        //Update Selected Items (for the case that objects were deleted) and UpdateSelection
        OnSelect();

        //UpdateSelection();
        this.Update();



现在这很有意思:


Now that's interesting stuff:

    if (mNodeToExpand != null)
        {
            mNodeToExpand.Expand();
            mNodeToExpand = null;
        }
}



这就是我试图实现我想要的东西,但节点没有扩展(它还有其他孩子) 。


This is how I tried to achieve what I want, but the node doesn't expand (it still has other children).
In the

Remove()

我也试过

mTreeView.SelectedNode.Parent.Nodes.Add(new Node("Blabla"));

但它甚至没有添加节点;

but it doesn't even add a node;

推荐答案

我假设在删除树正常运行之前,应该扩展它应该。你怎么删除它?我使用类似的东西:



pnode.Nodes [i] .Remove();



其中pnode是父节点。
I assume before deleting that the tree is operating normally, expanding when it should. How are you deleting it? I use something like:

pnode.Nodes[i].Remove();

where pnode is the parent node.


这篇关于Treeview - 节点不扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆