Cool top secret features fascinate me. Remember the hidden “Easter eggs” game in Excel 2002 (http://www.j-walk.com/ss/excel/eastereg.htm)? Don’t you love it when developers pull something up from their sleeve, which is so cool, people just brag about it for years?

Truth to be told, we have a secret feature in RadTreeView for WinForms as well. It may be not as cool as the “Easter eggs” Excel game, but is something I wanted to share with you for some time now. I like this one, because it is our small secret weapon in the war for dominating the world of software features.

RadTreeView has always had the ability to execute commands on a given sub-tree(including the entire tree node structure). This is done using the static Execute* methods of the RadTreeView class. These methods hide the complexity of the traversal algorithm and let you easily execute arbitrary actions over sub-trees of RadTreeNode objects. This way you do not have to worry about complex tree traversal algorithms and can concentrate on the action (or command) that you want to execute. For example these  methods can help you in finding a node by the value of its Text property – something our customers request quite a bit. All you need to do is write a simple command that compares the value of the Text property of a given node to a string. Here is the code for such a command:

public class FindNodeByTextCommand : CommandBase 
    public override object Execute(params object[] settings) 
    { 
        if (settings.Length > 1 && this.CanExecute(settings[0])) 
        { 
            RadTreeNode node = settings[0] as RadTreeNode; 
            string text = (settings[1] as IList)[0] as string
 
            if (node != null && !string.IsNullOrEmpty(text)) 
            { 
                if (node.Text == text) 
                { 
                    return node; 
                } 
            } 
        } 
        return null
    } 
 
    public override bool CanExecute(object parameter) 
    { 
        if (parameter is RadTreeNode) 
        { 
            return true
        } 
        return base.CanExecute(parameter); 
    } 

And you execute that command with code like:
RadTreeNode node = Telerik.WinControls.UI.RadTreeView.ExecuteScalarCommand(this.radTreeView1.Nodes, -1, 
        new FindNodeByTextCommand(), "Node"as RadTreeNode;  


The Execute* methods can also assist you in other interesting tasks. For example, you can easily set a property of all nodes to a given value in a sub-tree using the SetPropertyValueCommand that is already available.

One thing that must be noted is that these Execute* methods currently traverse the given sub-tree in Breadth First order (see http://en.wikipedia.org/wiki/Breadth-first_search) to allow executing a command only on a given level in a sub-tree.

So, do you think our top-secret weapon will help us dominate the world? Or maybe it can be improved? Or it is too complex? In case you like it, please let us know what additional traversal algorithms you want implemented. Depth First for example?  (see http://en.wikipedia.org/wiki/Depth-first_search)


Related Posts

Comments