检查/取消选中树形记录中的节点后如何中断

时间:2011-10-10 08:04:48

标签: treeview nodes treelist

我有点问题。 我应该为treeList实现一个逻辑,该逻辑由单个父节点组成,而更多的子节点由ID组成更多的组。

我有一个处理所有节点的动作:

long callerGroup = -1L;

if (callerNode != null)
{
    var service = this.tlServices.GetDataRecordByNode(callerNode) as __ServiceInfo;

    if (service != null)
    {
        callerGroup = service.Group;
    }
}

Action<TreeListNodes> action = null;

action = (nodes) =>
{
    if (nodes != null && nodes.Count > 0)
    {
        foreach (TreeListNode node in nodes)
        {
            if (node.Level == 0 && !node.Checked)
            {
                node.Checked = true;
                break;
            }
            else
            {
                var service = this.tlServices.GetDataRecordByNode(node) as __ServiceInfo;

                if (service != null)
                {
                    var group = service.Group;

                    //for ' 1 <= group <= 100' -> Mandatory Service, only ONE from group
                    if (callerGroup >= 1 && callerGroup <= 100)
                    {
                        if (group >= 1 && group <= 100)
                        {
                            //node.Checked = true; - not done
                        }
                    }

                    //for ' 101 <= group <= 1000 ' -> Mandatory Service, minimum ONE from group, but allow and MORE
                    if (callerGroup >= 101 && callerGroup <= 1000)
                    {

                    }

                    //for ' group >= 1001 ' -> optional Service, ALL from group
                    if (callerGroup >= 1001 && group >= 1001)
                    {
                        node.Checked = !node.Checked; // --> DONE. 
                    }
                }
            }
            action(node.Nodes);
        }
    }
};

action(this.tlServices.Nodes);

我有3个案例:

  • #1。如果 1&lt; = group&lt; = 100 - &gt;强制服务,只允许来自组
  • 中的一个
  • #2。如果 101&lt; = group&lt; = 1000 - &gt;强制服务,允许组中的最小ONE,但允许和更多
  • #3。 if group&gt; = 1001 - &gt;可选服务,选中/取消选中组中的所有内容。

结果: #3我做得很轻松,但我怎样才能实现#1。

1 个答案:

答案 0 :(得分:0)

对于#1我找到了一个实现:

//代表'1&lt; = group&lt; = 100' - &gt;强制服务,只有一组来自

if (callerGroup >= 1 && callerGroup <= 100)
                            {
                                if (group >= 1 && group <= 100)
                                {
                                    foreach (TreeListNode nd in nodes)
                                    {
                                        var svc = this.tlServices.GetDataRecordByNode(nd) as __ServiceInfo;
                                        long gr = svc.Group;

                                        if (gr == callerGroup && nd.Checked == true)
                                        {
                                            nd.Checked = false;
                                        }
                                    }
                                }
                            }`
相关问题