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

Delete "Group by" option from Header Context Filter Menu

4 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aitor
Top achievements
Rank 1
Aitor asked on 04 Aug 2011, 01:41 PM
Hi,

I think the title of this thread is clear enough to know what I really want to get, isnĀ“t it? :-)

I want somehow to access to filter options of header context menu and delete "Group by" and "Ungroup" options from this menu. Is is possible?

Thank you in advance

4 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Aug 2011, 01:59 PM

Hello Aitor,


protected void Page_Load(object sender, EventArgs e)
    {
        RadGrid1.HeaderContextMenu.ItemCreated += this.HeaderContextMenu_ItemCreated;
    }
    private void HeaderContextMenu_ItemCreated(object sender, RadMenuEventArgs e)
    {
        switch ((e.Item.Text))
        {
            case "Group By":
                e.Item.Visible = false;
                //e.Item.Text = "New Text"; you can also change text
                break;
            case "Ungroup":
                e.Item.Visible = false;
                break;
        }
    }

if you get two separator after hiding the group and ungroup option then you can try below solution.
public int count
{
    get
    {
        if (ViewState["Count"] != null)
            return Convert.ToInt32(ViewState["Count"]);
        else
            return 0;
    }
    set
    {
        ViewState["Count"] = value;
    }
}
 
protected void Page_Load(object sender, EventArgs e)
{
    RadGrid1.HeaderContextMenu.ItemCreated += this.HeaderContextMenu_ItemCreated;
}
private void HeaderContextMenu_ItemCreated(object sender, RadMenuEventArgs e)
{
    switch ((e.Item.Text))
    {
        case "Group By":
            e.Item.Visible = false;
            count++;
            //e.Item.Text = "New Text"; you can also change text
            break;
        case "Ungroup":
            e.Item.Visible = false;
            count++;
            break;
        case "":
            if (count == 2)
            {
                e.Item.Visible = false;
                count = 0;
            }
            break;
          Default:
                    count =0;
                             break;
    }
}



let me know if any concern.

Thanks,
Jayesh Goyani
0
Accepted
Shinu
Top achievements
Rank 1
answered on 04 Aug 2011, 02:02 PM
Hello Aitor,

Please try using the following code in order to remove the "Group By" and "UnGroup" items.
protected void Page_Load(object o, EventArgs e)
{
    RadGrid1.HeaderContextMenu.ItemCreated += new RadMenuEventHandler(HeaderContextMenu_ItemCreated);
}
  
void HeaderContextMenu_ItemCreated(object sender, RadMenuEventArgs e)
{
    if (e.Item.Text == "Group By")
    {
        e.Item.Style.Add("display", "none");
        (sender as RadContextMenu).Items[e.Item.Index - 1].Remove();
    }
      if (e.Item.Text == "UnGroup")
    {
        e.Item.Style.Add("display", "none");
        (sender as RadContextMenu).Items[e.Item.Index - 1].Remove();
    }

}

Thanks,
Shinu.
0
Aitor
Top achievements
Rank 1
answered on 05 Aug 2011, 01:21 PM
Thank you very much!
0
July
Top achievements
Rank 2
answered on 03 Nov 2011, 07:17 PM
This post resolve my doubts quickly! thanks
Tags
Grid
Asked by
Aitor
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Shinu
Top achievements
Rank 1
Aitor
Top achievements
Rank 1
July
Top achievements
Rank 2
Share this question
or