Disable group sorting

3 posts, 1 answers
  1. Ilya
    Ilya avatar
    7 posts
    Member since:
    Dec 2012

    Posted 13 Oct 2015 Link to this post

    Greetings!

     I`m trying to attach context menu to a GroupFieldElement (those boxes in group panel when groupping applied) to add possibility to expand\collapse whole group.

    Everything's ok, but both mouse clicks (left\right) call group sorting event and i cannot get rid of this behavior (tried even with RadGridBehavior and overriding OnMouseUp\Down). So, how can i disable sorting event when i click on group definition in group panel with right mouse click?

     Thank you!

     

  2. Answer
    Dess
    Admin
    Dess avatar
    1608 posts

    Posted 16 Oct 2015 Link to this post

    Hello Ilya,

    Thank you for writing.
     
    Here is a sample code snippet demonstrating how to show a RadContextMenu with right mouse click over a GroupFieldElement and keep the ListSortDirection. The attached gif file illustrates the behavior on my end:
    RadContextMenu menu = new RadContextMenu();
     
    public Form1()
    {
        InitializeComponent();
        
        RadMenuItem item1 = new RadMenuItem("Expand Groups");
        item1.Click += item1_Click;
        RadMenuItem item2 = new RadMenuItem("Collapse Groups");
        item2.Click += item2_Click;
        menu.Items.Add(item1);
        menu.Items.Add(item2);
        this.radGridView1.MouseDown += radGridView1_MouseDown;
        this.radGridView1.MouseUp += radGridView1_MouseUp;
    }
     
    private void radGridView1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            GroupFieldElement el = this.radGridView1.ElementTree.GetElementAtPoint(e.Location).FindDescendant<GroupFieldElement>() ;
            if (el != null && this.radGridView1.Tag != null)
            {
                ListSortDirection direction = (ListSortDirection)this.radGridView1.Tag;
                if (direction != null)
                {
                    el.SortDescription.Direction = direction;
                }
            }
        }
    }
     
    private void radGridView1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            GroupFieldElement el = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GroupFieldElement;
            if (el != null)
            {
                this.radGridView1.Tag = el.SortDescription.Direction;
                Point p = (sender as Control).PointToScreen(e.Location);
                menu.Show(p.X, p.Y);
            }
        }
    }
     
    private void item2_Click(object sender, EventArgs e)
    {
        foreach (GridViewGroupRowInfo g in this.radGridView1.ChildRows)
        {
            g.IsExpanded = false;
        }
    }
     
    private void item1_Click(object sender, EventArgs e)
    {
        foreach (GridViewGroupRowInfo g in this.radGridView1.ChildRows)
        {
            g.IsExpanded = true;
        }
    }

    Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ilya
    Ilya avatar
    7 posts
    Member since:
    Dec 2012

    Posted 16 Oct 2015 in reply to Dess Link to this post

    Thank you very much! That`s great!)
Back to Top