Home / Community & Support / Knowledge Base / RadControls for ASP.NET AJAX / FileExplorer / Remove the "Delete" and "Upload" commands from the RadFileExplorer control

Remove the "Delete" and "Upload" commands from the RadFileExplorer control

Article Info

Rating: 5

 

Article information

Article relates to

RadFileExplorer 

Created by

 Fiko, Telerik

Last modified

 May 20, 2009

Last modified by

 Fiko, Telerik



HOW-TO

Remove command(s) from the toolbar and context menus in the RadFiileExplorer control. The example is about removing the "Delete" and "Upload"  commands, but the same approach can be applied for any of the remaining commands.

First we need to get reference to all of the objects that contain the "Delete" and "Upload" commands, and then remove the commands. The embedded into RadFileExplorer controls that need to be affected are :  RadToolBar, RadTreeView's context menu, RadGrid's context menu. This can be done as follows :
  • RadToolBar - RadFileExplorer1.ToolBar
  • RadtreeView's context menu - RadFileExplorer1.TreeView.ContextMenu[0]. The RadToolBarItemCollection contains only one context menu and we get reference to that one.
  • RadGrid's context menu - RadFileExplorer1.GridContextMenu

Then we can use the following approach in order to remove the commands :

C# :

        RadToolBar toolBar = fileExplorer.ToolBar;  
        // Remove commands from the ToolBar control;  
        i = 0;  
        while (i < toolBar.Items.Count)  
        {  
            if (toolBar.Items[i].Value == "Delete")  
            {  
                toolBar.Items.RemoveAt(i);  
                continue;// Next item  
            }  
 
            else if (toolBar.Items[i].Value == "Upload")  
            {  
                toolBar.Items.RemoveAt(i);  
                continue// Next item  
            }  
 
            i++;// Next item  
        } 

VB.NET :

        Dim toolBar As RadToolBar = fileExplorer.ToolBar  
        ' Remove commands from the ToolBar control;  
        i = 0  
        While i < toolBar.Items.Count  
            If toolBar.Items(i).Value = "Delete" Then 
                toolBar.Items.RemoveAt(i)  
                ' Next item  
                Continue While 
 
            ElseIf toolBar.Items(i).Value = "Upload" Then 
                toolBar.Items.RemoveAt(i)  
                ' Next item  
                Continue While 
            End If 
 
            ' Next item  
            i += 1  
        End While 

The same approach can be applied to the RadTreeView's context menu and RadGrid's context menu.
Please do not forget to use the continue statement in case that an item is deleted. The statement is used in order to avoid an error like : "Index was out of range...".

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.