Disable sorting on left mouse click

7 posts, 0 answers
  1. Patryk
    Patryk avatar
    6 posts
    Member since:
    Jul 2013

    Posted 09 Sep 2013 Link to this post

    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?
  2. Patryk
    Patryk avatar
    6 posts
    Member since:
    Jul 2013

    Posted 10 Sep 2013 Link to this post

    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);
          }
    }
  3. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 12 Sep 2013 Link to this post

    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 >>
  4. Patryk
    Patryk avatar
    6 posts
    Member since:
    Jul 2013

    Posted 13 Sep 2013 Link to this post

    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.
  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4004 posts

    Posted 17 Sep 2013 Link to this post

    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 >>
  6. Patryk
    Patryk avatar
    6 posts
    Member since:
    Jul 2013

    Posted 19 Sep 2013 Link to this post

    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?
  7. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4004 posts

    Posted 24 Sep 2013 Link to this post

    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 >>
Back to Top