Friday, November 19, 2010

RadTreeView Commands Overview

RadTreeView implements the Command pattern which allows adding functionality, which operates on RadTreeNodes, without needing to modify the code of RadTreeView. This makes it easy for developers to create their own commands should they find that the commands, which RadTreeView provides, are insufficient.

RadTreeView exposes two methods with two overloads each, which accept commands to execute. The methods are called ExecuteScalarCommand() and ExecuteBatchCommand(). The difference between those two methods is that ExecuteScalarCommand() works on a single RadTreeNode whereas ExecuteBatchCommand() works on many nodes. For example, if a command which searches for a node with specific text, is passed to ExecuteScalarCommand() only one node will be found and returned. Passing it to ExecuteBatchCommand will find all nodes that have this text and return all of them. The methods return object and List<Object> (List (Of Object) in VB) which means that commands are not required to return RadTreeNodes. For example you can search for nodes and when they are found, custom objects may be created and returned. This capability will be discussed in the Implementing Custom Commands topic.

Here is an abstract example of how commands are used with RadTreeView.

Command cmd = new Command();
List<object> result = RadTreeView.ExecuteBatchCommand(nodeCollection, -1, cmd, commandParam1, commandParam2);
if(result != null)
// Found nodes.

Dim cmd As Command = New Command
Dim result As List(Of Object) = RadTreeView.ExecuteBatchCommand(nodeCollection, -1, cmd, commandParam1, commandParam2)
If Not result Is Nothing Then
'Found nodes.
End If 

The example above creates a Command object and passes it to the ExecuteBatchCommand() method of RadTreeView. The method accepts a node collection on which the command will be executed, the nesting level of the nodes which will be affected, the command object and parameters which the particular command accepts. The level in this case is -1 which indicates that the whole node hierarchy will be affected by the command.

The ExecuteScalarCommand() method is used in the exact same way with the difference that it affects only one node, and only one node is returned.

Dev ComponentsRadControls for WinFormsTelerik Windows Forms RadTreeView

Source of Information :  2002-2010 Telerik. All Rights Reserved. Help
RadTreeView Commands OverviewSocialTwist Tell-a-Friend
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments: on "RadTreeView Commands Overview"

Post a Comment