[英]DevExpress - Select multiple checkboxes in TreeList
Let's say if I have a TreeList of 2 groups, teachers and students, there is a column of "Status".假设我有一个包含教师和学生 2 个组的 TreeList,其中有一列“状态”。 I'm trying to implement a button to select all groups of teachers and students who are active.我正在尝试为所有活跃的教师和学生组实现 select 按钮。
This is what I have so far这是我到目前为止所拥有的
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);
}
}
Then, I called it from my TreeList class然后,我从我的 TreeList class 中调用它
MatchStatusOps operation = new MatchStatusOps("Status","Active",this);
this.NodesIterator.DoOperation(operation);
I cannot make the check boxes selected, I think it may be because the node selected is the status nodes, not the checkbox nodes?我无法选中复选框,我认为可能是因为选中的节点是状态节点,而不是复选框节点? Any ideas I could make it work?有什么想法可以让它发挥作用吗? Thanks.谢谢。
I think it may be because the node selected is the status nodes, not the checkbox nodes我认为可能是因为选择的节点是状态节点,而不是复选框节点
Those are not nodes, those are columns (usually bound by field name).那些不是节点,那些是列(通常由字段名称绑定)。 A node can contain any number of columns.一个节点可以包含任意数量的列。
Further, this line of code ensures your operation is running across all nodes:此外,这行代码可确保您的操作在所有节点上运行:
NodesIterator.DoOperation(operation);
The code below is based on an educated guess about your data source or code that populates the TreeList
(if unbound) from the screenshot.下面的代码基于对您的数据源或从屏幕截图中填充TreeList
(如果未绑定)的代码的有根据的猜测。
Code:代码:
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;
}
}
Usage:用法:
var operation = new MatchStatusOps("Status","Active","YourCheckboxFieldName");
NodesIterator.DoOperation(operation);
Note I'm setting a column on a given node to checked, not the node itself.注意我将给定节点上的列设置为检查,而不是节点本身。
Confirmed working on my end with latest DevExpress version as of this writing.在撰写本文时,已确认使用最新的 DevExpress 版本为我工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.