Back to Devexpress

ResourceTreeControl.Commands Property

wpf-devexpress-dot-xpf-dot-scheduling-dot-resourcetreecontrol-4b765674.md

latest4.0 KB
Original Source

ResourceTreeControl.Commands Property

Provides access to the set of available resource tree commands.

Namespace : DevExpress.Xpf.Scheduling

Assembly : DevExpress.Xpf.Scheduling.v25.2.dll

NuGet Package : DevExpress.Wpf.Scheduling

Declaration

csharp
public ResourceTreeCommands Commands { get; set; }
vb
Public Property Commands As ResourceTreeCommands

Property Value

TypeDescription
ResourceTreeCommands

A DevExpress.Xpf.Scheduling.ResourceTreeCommands object that provides a set of resource tree commands.

|

Remarks

You can use the Commands property to programmatically execute a resource tree command.

The example below illustrates how to substitute the default DeleteCommand execution with a custom method defined in the ViewModel using the DXCommand binding tool.

xaml
<dxsch:ResourceTreeControl Name="resourceTreeControl" Scheduler="{Binding ElementName=scheduler}">
                <dxsch:ResourceTreeControl.Commands >
                    <dxsch:ResourceTreeCommands DeleteCommand="{DXCommand Execute='MyDeleteCommand(@e(resourceTreeControl))'}" />
                </dxsch:ResourceTreeControl.Commands>
            </dxsch:ResourceTreeControl>
csharp
public void MyDeleteCommand(DevExpress.Xpf.Scheduling.ResourceTreeControl resourceTree) {
            //obtain the handle of the row for which the menu has been invoked
            int selectedRowHandle = resourceTree.TreeList.GetSelectedNodes()[0].RowHandle;
            //check whether the menu has been invoked for a group row
            if (resourceTree.TreeView.GetNodeByRowHandle(selectedRowHandle).HasChildren) {
                //iterate through resources in the group and clear their Group property value
                TreeListNodeIterator nodeIterator = new TreeListNodeIterator(resourceTree.TreeList.GetSelectedNodes()[0].Nodes);
                while (nodeIterator.MoveNext())
                    (resourceTree.TreeList.GetRow(nodeIterator.Current.RowHandle) as ResourceItem).Group = null;
            }
            //remove the row for which the menu has been invoked
            resourceTree.TreeView.DeleteNode(selectedRowHandle);
        }
vb
Public Sub MyDeleteCommand(ByVal resourceTree As DevExpress.Xpf.Scheduling.ResourceTreeControl)
            'obtain the handle of the row for which the menu has been invoked
            Dim selectedRowHandle As Integer = resourceTree.TreeList.GetSelectedNodes()(0).RowHandle
            'check whether the menu has been invoked for a group row
            If resourceTree.TreeView.GetNodeByRowHandle(selectedRowHandle).HasChildren Then
                'iterate through resources in the group and clear their Group property value
                Dim nodeIterator As New TreeListNodeIterator(resourceTree.TreeList.GetSelectedNodes()(0).Nodes)
                Do While nodeIterator.MoveNext()
                    TryCast(resourceTree.TreeList.GetRow(nodeIterator.Current.RowHandle), ResourceItem).Group = Nothing
                Loop
            End If
            'remove the row for which the menu has been invoked
            resourceTree.TreeView.DeleteNode(selectedRowHandle)
        End Sub

See Also

ResourceTreeControl Class

ResourceTreeControl Members

DevExpress.Xpf.Scheduling Namespace