【问题标题】:DevExpress - Select multiple checkboxes in TreeListDevExpress - 在 TreeList 中选择多个复选框
【发布时间】:2021-01-22 23:02:09
【问题描述】:

假设我有一个包含教师和学生 2 个组的 TreeList,其中有一列“状态”。我正在尝试实现一个按钮来选择所有活跃的教师和学生组。

这是我目前所拥有的

public class MatchStatusOps : TreeListOperation
{
    private string fieldName;
    private string status;
    private TreeList helper;

    public TreeListMatchStatusOperation(string fieldName, string status,TreeList helper)
    {
        this.fieldName = fieldName;
        this.status = status;
        this.helper = helper;
    }

    public override void Execute(TreeListNode node)
    {
        String statusValue = Convert.ToString(node[fieldName]);
        if (statusValue.Equals(status))
            helper.SetNodeCheckState(node, CheckState.Checked, true);
    }
}

然后,我从我的 TreeList 类中调用它

MatchStatusOps operation = new MatchStatusOps("Status","Active",this);
this.NodesIterator.DoOperation(operation);

我无法选中复选框,我想可能是因为选中的节点是状态节点,而不是复选框节点?有什么想法可以让它发挥作用吗?谢谢。

【问题讨论】:

    标签: c# asp.net devexpress devexpress-windows-ui


    【解决方案1】:

    我认为可能是因为选择的节点是状态节点,而不是复选框节点

    那些不是节点,那些是列(通常由字段名称绑定)。一个节点可以包含任意数量的列。

    此外,这行代码可确保您的操作在所有节点上运行:

    NodesIterator.DoOperation(operation);
    

    以下代码基于对您的数据源或填充屏幕截图中TreeList(如果未绑定)的代码的有根据的猜测。

    代码:

    public class MatchStatusOps : TreeListOperation
    {
        private readonly string fieldName;
        private readonly string status;
        private readonly string checkboxFieldName;
    
        public MatchStatusOps(string fieldName, string status, string checkboxFieldName)
        {
            this.fieldName = fieldName;
            this.status = status;
            this.checkboxFieldName = checkboxFieldName;
        }
    
        public override void Execute(TreeListNode node)
        {
            String statusValue = Convert.ToString(node[fieldName]);
            if (statusValue.Equals(status))
                node[checkboxFieldName] = true;
        }
    }
    

    用法:

    var operation = new MatchStatusOps("Status","Active","YourCheckboxFieldName");
    NodesIterator.DoOperation(operation);
    

    请注意,我在给定节点上设置了一个 来检查,而不是节点本身。

    确认在撰写本文时使用最新的 DevExpress 版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-24
      相关资源
      最近更新 更多