how to use tree list nodeiterator in devexpress c# code example

Example: how to use tree list nodeiterator in devexpress c#

// 1 create new class to override Execute function:
    public class TreeOperation: TreeListOperation
    {
        private readonly SolidWorksPpsType pps;
        public TreeOperation(SolidWorksPpsType ppsType)
        {
            pps = ppsType;
        }
        public override void Execute(TreeListNode node)
        {
            if(!(node.Tag is SolidWorksPositionsModel model ))return;

            if (model.Type == pps)
            {
                node.Checked = true;
                model.IsChecked = true;
            }
            else if (pps == SolidWorksPpsType.All)
            {
                node.Checked = true;
                model.IsChecked = true;
            }

        }
    }
    
// 2 Use this class like this:
        public static void FilterObjectList(IContext context,TreeList treeList,SolidWorksPpsType ppsType, object sender, EventArgs args)
        {
            try
            {
                var operation = new TreeOperation(ppsType);
                treeList.NodesIterator.DoOperation(operation);
            }
            catch (Exception e)
            {
                context.Logger.Log(new LogMessage(Level.Error, "Error occurred while creating a subset from cad list ", e));
            }

        }

Tags:

Misc Example