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

How to control list of columns that are available in Conditional Formatting Rules Manager?

1 Answer 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 12 Jul 2011, 03:24 PM

Hi!

By default all properties from row object (databound item) goes to Conditional Formatting Rules Manager.

You can take a look at the attachment. 

  1. How can I select which columns should be available in this window?
  2. Can I somehow disable conditional formatting for whole grid? How to remove this option from column header context menu?

 

I have found option for hidding column chooser: radGridView1.AllowColumnChooser but I cannot find similar option for hiding conditional formatting.

 

 

 

 

 

Regards

1 Answer, 1 is accepted

Sort by
0
Accepted
Svett
Telerik team
answered on 15 Jul 2011, 09:39 AM
Hi Raymond,

You can achieve the desired behavior by handling the ContextMenuOpening event of RadGridView. In addition, you need to extend the ConditionalFormattingForm form:

private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
    GridHeaderCellElement headerCell = e.ContextMenuProvider as GridHeaderCellElement;
 
    if (headerCell == null)
    {
        return;
    }
 
    bool removeMenu = headerCell.ColumnInfo.Name == "ColumnWhichDoesNotSupportConditionalFormatting";
    string name = RadGridLocalizationProvider.CurrentProvider.GetLocalizedString(RadGridStringId.ConditionalFormattingMenuItem);
 
    for (int i = e.ContextMenu.Items.Count - 1; i >= 0; i--)
    {
        RadMenuItem menuItem = e.ContextMenu.Items[i] as RadMenuItem;
 
        if (menuItem == null || menuItem.Text != name)
        {
            continue;
        }
 
        e.ContextMenu.Items.RemoveAt(i);
 
        if (!removeMenu)
        {
            menuItem = new RadMenuItem(name);
            menuItem.Tag = headerCell;
            menuItem.Click += new EventHandler(menuItem_Click);
            e.ContextMenu.Items.Insert(i, menuItem);
            break;
        }
    }
}

public class MyConditionalFormattingForm : ConditionalFormattingForm
{
    public MyConditionalFormattingForm(GridHeaderCellElement cell)
        : base(cell.ViewTemplate, cell.ColumnInfo as GridViewDataColumn)
    {
 
    }
 
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
 
        RadDropDownList list = this.Controls.Find("radComboBoxColumns", true)[0] as RadDropDownList;
        string columnToRemove = "ColumnDoesNotSupportConditionalFormatting";
 
        for (int i = list.Items.Count - 1; i >= 0; i--)
        {
            RadListDataItem item = list.Items[i];
 
            if (item.Text.Contains(columnToRemove))
            {
                list.Items.Remove(item);
                break;
            }
        }
    }
}

I hope this helps.

Best wishes,
Svett
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or