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

Disable group sorting

2 Answers 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ilya
Top achievements
Rank 1
Ilya asked on 13 Oct 2015, 04:54 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Oct 2015, 08:28 AM
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
0
Ilya
Top achievements
Rank 1
answered on 16 Oct 2015, 08:53 AM
Thank you very much! That`s great!)
Tags
GridView
Asked by
Ilya
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Ilya
Top achievements
Rank 1
Share this question
or