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

RadGridView and sort

2 Answers 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Volle Bertrand
Top achievements
Rank 1
Volle Bertrand asked on 11 Aug 2009, 06:26 AM
Hello,

I would like to remove the sort when clicking on a column header and develop my own context menu which contains a "sort" item calling the telerik sort methods.

The only way I found to remove the sort with the header consists in setting to false the property EnableSorting. But if I do this the sorting method of the API doesn't work anymore.

Can you help me?

Thanks
bertrand

2 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 11 Aug 2009, 11:15 AM
Hi Volle Bertrand,

Thank you for contacting us.

You can disable the sorting in grid header cells by using custom cells. They should inherit from GridHeaderCellElement. You should also override OnMouseUp event to intercept mouse messages. Here is a sample:

void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e) 
    if (e.CellType == typeof(GridHeaderCellElement)) 
    { 
        e.CellType = typeof(MyHeaderCell); 
    } 
 
public class MyHeaderCell : GridHeaderCellElement 
    public MyHeaderCell(GridViewColumn column, GridRowElement row) 
        : base(column, row) 
    { } 
 
    protected override Type ThemeEffectiveType 
    { 
        get { return typeof(GridHeaderCellElement); } 
    } 
 
    protected override void OnMouseUp(MouseEventArgs e) 
    { 
        //base.OnMouseUp(e); 
    } 

Please handle ContextMenuOpening event to replace the default sorting action:

void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e) 
    if (e.ContextMenuProvider is MyHeaderCell) 
    { 
        for (int i = 0; i < 3; i++) 
        { 
            e.ContextMenu.Items.RemoveAt(0); 
        } 
        e.ContextMenu.Items.Insert(0, new RadMenuItem("Custom sort")); 
    } 

I hope this helps. If you have more questions, I will be glad to assist you.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Volle Bertrand
Top achievements
Rank 1
answered on 11 Aug 2009, 11:31 AM
thanks a lot. it works!

Bertrand
Tags
GridView
Asked by
Volle Bertrand
Top achievements
Rank 1
Answers by
Jack
Telerik team
Volle Bertrand
Top achievements
Rank 1
Share this question
or