Grid_ HeaderContexMenu hide "Columns" element from the list cause error

4 posts, 1 answers
  1. archimede
    archimede avatar
    103 posts
    Member since:
    Jul 2006

    Posted 05 Oct 2011 Link to this post

    Hi,
    I'd like to show only Group and Ungroup  options on the headercontext menu of a RadGrid so i've done in this way
    void HeaderContextMenu_ItemCreated(object sender, RadMenuEventArgs e)
           {
               switch (e.Item.Text)
               {                
                   case "Columns": e.Item.Visible = false;break;               
                   case "Sort Ascending": e.Item.Visible = false; break;
                   case "Sort Descending": e.Item.Visible = false; break;
                   case "Clear Descending": e.Item.Visible = false; break;
                   case "Clear Sorting": e.Item.Visible = false; break;
                          }
           }
    If i leave the "element "Columns visible" it works fine, but if i putcase "Columns": e.Item.Visible = false;break;  i get this error:
    Microsoft JScript runtime error: 'findItemByValue(...)' is null or not an object

    What is the problem of  hiding the item "Columns" of the context mennu ?

    Thank You !!

  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Oct 2011 Link to this post

    Hello Archimede,

    Try the following code snippet to show only Group and Ungroup options on the HeaderContext menu.
    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
     RadGrid1.HeaderContextMenu.ItemCreated += new RadMenuEventHandler(HeaderContextMenu_ItemCreated);
    }
    void HeaderContextMenu_ItemCreated(object sender, RadMenuEventArgs e)
    {
        if (e.Item.Text == "Columns")
        {
            e.Item.Style.Add("display", "none");
            (sender as RadContextMenu).Items[e.Item.Index - 1].Remove();
        }
         if (e.Item.Text == "Filter")
        {
            e.Item.Style.Add("display", "none");
            (sender as RadContextMenu).Items[e.Item.Index - 1].Remove();
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. archimede
    archimede avatar
    103 posts
    Member since:
    Jul 2006

    Posted 10 Oct 2011 Link to this post

    Hi,
    Thanks for your answer, It works !!
    I just made a little modified, i only use e.Item.Style.Add("display", "none");, because with .."remove" .. when i click on Group by, the element Ungroup disapear.

    Thanks again !!.
  5. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 10 Oct 2011 Link to this post

    Hello Archimede,

    Please find the attached sample and see if it works for your case.

    All the best,
    Iana Tsolova
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top