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

Disable sorting on left mouse click

6 Answers 59 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Patryk
Top achievements
Rank 1
Patryk asked on 09 Sep 2013, 10:21 AM
Hello
I want to disable sorting on left mouse click on header cell, but still enable on context menu click.
How can I achieve this?

6 Answers, 1 is accepted

Sort by
0
Patryk
Top achievements
Rank 1
answered on 10 Sep 2013, 08:51 AM
I found a solution:
radGridView1.GridBehavior = new CustomGridBehavior();
 
private class CustomGridBehavior : BaseGridBehavior
{
      public override bool OnMouseDown(MouseEventArgs e)
      {
          var cell = this.GridControl.ElementTree.GetElementAtPoint(e.Location) as GridHeaderCellElement;
          if (cell != null && e.Button == MouseButtons.Left)
          {
              return false;             
          }
          return base.OnMouseDown(e);
      }
}
0
Stefan
Telerik team
answered on 12 Sep 2013, 09:04 AM
Hello Patryk,

I can confirm that this is the recommended way to achieve the desired functionality. Should you have any other questions do not hesitate to contact us.

Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Patryk
Top achievements
Rank 1
answered on 13 Sep 2013, 07:58 AM
It should be:

private class CustomGridBehavior : BaseGridBehavior
{
    private bool _isSort;
 
    public override bool OnMouseDown(MouseEventArgs e)
    {
        var cell = this.GridControl.ElementTree.GetElementAtPoint(e.Location) as GridHeaderCellElement;
        if (cell != null && e.Button == MouseButtons.Left)
        {
            _isSort = true;
        }
        return base.OnMouseDown(e);
    }
 
    public override bool OnMouseMove(MouseEventArgs e)
    {
        _isSort = false;
        return base.OnMouseMove(e);
    }
 
    public override bool OnMouseUp(MouseEventArgs e)
    {
        var cell = this.GridControl.ElementTree.GetElementAtPoint(e.Location) as GridHeaderCellElement;
        if (cell != null && e.Button == MouseButtons.Left && _isSort)
        {
            return false;             
        }
        return base.OnMouseUp(e);
    }
}

My previous version broke grouping, column resizing and column order changing.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Sep 2013, 03:59 PM
Hello Patryk,

Thank you for writing back and for the shared solution.

In order to change the default BaseGridBehavior, the recommended approach is to implement your own one just like you did. Thus you can handle all mouse or key inputs and change their behaviour if it is necessary. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Patryk
Top achievements
Rank 1
answered on 19 Sep 2013, 07:24 AM
There is one broken thing with my approach, check this scenario:
1. left-click on header - nothing
2. left-click on excel-like filtering button on header - starts sorting
How can I get rid of this unexpected behaviour?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Sep 2013, 05:48 AM
Hello Patryk,

Thank you for contacting Telerik Support.

I have not succeeded to reproduce the second scenario described in your previous post: left-click on excel-like filtering button on header starts sorting - it just opens Filtering popup on my end. Could you please specify what are the exact steps you perform to enable sorting in this scenario? And which version do you use? A sample project will be really appreciated. Thank you in advance.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Patryk
Top achievements
Rank 1
Answers by
Patryk
Top achievements
Rank 1
Stefan
Telerik team
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or