Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

c# - 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". I'm trying to implement a button to select all groups of teachers and students who are active.

enter image description here

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

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.

question from:https://stackoverflow.com/questions/65853911/devexpress-select-multiple-checkboxes-in-treelist

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...