是否有动态设置xtra树列表节点的可见性

时间:2013-05-20 10:52:01

标签: c# devexpress xtratreelist devexpress-windows-ui

我在我的应用程序中使用xtratreelist只有第一级,我想让一些节点可见但不是全部。这是代码,但之后所有不在列表中显示

TreeList tr = new Treelist();

for (int x = 0; x < tr.Nodes.Count; x++)
{
    tr.Nodes[x].Visible = false;
}

2 个答案:

答案 0 :(得分:1)

我建议您使用NodesIterator,这是一个示例,它适用于我:

数据类:

public class Service
{
    public string Name { get; set; }
    public bool Visible { get; set; }
}

以我的形式:

private void TreeForm_Load(object sender, EventArgs e)
{
     treeList1.DataSource = Service.GetServices();
     treeList1.NodesIterator.DoLocalOperation(setNodeVisibility, treeList1.Nodes);
}

private void setNodeVisibility(DevExpress.XtraTreeList.Nodes.TreeListNode node)
{
     var service = treeList1.GetDataRecordByNode(node) as Service;
     if (service == null)
         return;

     node.Visible = service.Visible;
}

答案 1 :(得分:0)