Is there a way to hide Conditional Formatting?

6 posts, 2 answers
  1. Chad Hensley
    Chad Hensley avatar
    54 posts
    Member since:
    Feb 2005

    Posted 19 Apr 2010 Link to this post

    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
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 21 Apr 2010 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. David
    David avatar
    3 posts
    Member since:
    Jul 2012

    Posted 26 Apr 2012 Link to this post

    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.
  5. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 27 Apr 2012 Link to this post

    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
  6. David
    David avatar
    3 posts
    Member since:
    Jul 2012

    Posted 27 Apr 2012 Link to this post

    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.
  7. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 27 Apr 2012 Link to this post

    Hi David, 

    All the localization strings for the RadGridView can be found here
    Hope this helps
    Richard
Back to Top
UI for WinForms is Visual Studio 2017 Ready