This is a migrated thread and some comments may be shown as answers.

Is there a way to hide Conditional Formatting?

5 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chad Hensley
Top achievements
Rank 1
Chad Hensley asked on 20 Apr 2010, 12:34 AM
When a user right-clicks on a row, I don't want them to see conditional formatting.  Is there a setting or programmatic way to disable or remove it from the list of options?  How about the other options?

Thanks

Chad

5 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 21 Apr 2010, 02:28 PM
Hello Chad Hensley,

Yes, you can do that by subscribing for the ContextMenuOpening event. You can use the following code snippet that removes the desired menu item:

private void radGridView_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
    RadMenuItemBase item = this.GetRadMenuItemByText(e.ContextMenu, "Conditional Formatting");
    if (item != null)
    {
        e.ContextMenu.Items.Remove(item);
    }
}
 
private RadMenuItemBase GetRadMenuItemByText(RadDropDownMenu menu, string title)
{
    foreach (RadMenuItemBase item in menu.Items)
    {
        if (item.Text == title)
        {
            return item;
        }
    }
 
    return null;
}



Greetings,
Svett
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
David
Top achievements
Rank 1
answered on 26 Apr 2012, 07:26 PM
This is a dangerous way to remove the item. It would only work when the English language is used. If localization occured it would not work. Is there no way to remove or disable the item based on the name of the menu item not the text. The name of the menu item is usually not localized.
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 27 Apr 2012, 09:33 AM
Hi David, 

The RadMenuItemBase does not have a name property. 
Instead, you can get the localized string back from the provider. 

private void radGridView_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
    RadMenuItemBase item = this.GetRadMenuItemByText(e.ContextMenu, RadGridLocalizationProvider.CurrentProvider.GetLocalizedString("ConditionalFormattingMenuItem"));
    if (item != null)
    {
        e.ContextMenu.Items.Remove(item);
    }
}
 
private RadMenuItemBase GetRadMenuItemByText(RadDropDownMenu menu, string title)
{
    foreach (RadMenuItemBase item in menu.Items)
    {
        if (item.Text == title)
        {
            return item;
        }
    }
 
    return null;
}

This way, it doesn't matter what the menu is localized to, it will always get the correct one. 

Hope that helps
Richard
0
David
Top achievements
Rank 1
answered on 27 Apr 2012, 02:27 PM
Is there a list of what the names of these items for menus are? This is a much better way that using the English Text property information.
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 27 Apr 2012, 02:34 PM
Hi David, 

All the localization strings for the RadGridView can be found here
Hope this helps
Richard
Tags
GridView
Asked by
Chad Hensley
Top achievements
Rank 1
Answers by
Svett
Telerik team
David
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Share this question
or