Disabling sort on individual columns. How?

9 posts, 1 answers
  1. Czeshirecat
    Czeshirecat avatar
    62 posts
    Member since:
    Jun 2016

    Posted 22 Oct 2018 Link to this post

    I've an image column where sorting is invalid. I've found no info googling for a solution to disabling sort on radvirtualgrid columns.

    How do I do that please?

    (I've an event handler that prevents sorting on that column programatically, but I don't want to see either the little direction arrows on the column header, or a context menu)

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3331 posts

    Posted 22 Oct 2018 Link to this post

    Hello, Claire, 

    In order to disable sorting for a certain column in RadVirtualGrid, it is appropriate to create a custom VirtualGridInputBehavior and override its HandleMouseUp method. Thus, you can prevent the default logic for sort changing considering the column index of the header cell. You can find below a sample code snippet:

    public RadForm1()
    {
        InitializeComponent();
     
        this.radVirtualGrid1.RowCount = 100;
        this.radVirtualGrid1.ColumnCount = 5;
        this.radVirtualGrid1.CellValueNeeded += radVirtualGrid1_CellValueNeeded;
     
        this.radVirtualGrid1.VirtualGridElement.InputBehavior = new CustomVirtualGridInputBehavior(this.radVirtualGrid1.VirtualGridElement);
    }
     
    public class CustomVirtualGridInputBehavior : VirtualGridInputBehavior
    {
        public CustomVirtualGridInputBehavior(RadVirtualGridElement gridElement) : base(gridElement)
        {
        }
     
        public override bool HandleMouseUp(MouseEventArgs args)
        {
            VirtualGridHeaderCellElement headerCell = this.GridElement.ElementTree.GetElementAtPoint(args.Location) as VirtualGridHeaderCellElement;
            if (headerCell != null && headerCell.ColumnIndex == 2)
            {
                return false;
            }
            return base.HandleMouseUp(args);
        }
    }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Czeshirecat
    Czeshirecat avatar
    62 posts
    Member since:
    Jun 2016

    Posted 23 Oct 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    thanks very much for that. It works great to prevent the sort event from occuring, but the context menu pops up when right clicked and contains the sort options. Selecting these causes the direction arrow on the header to appear even tho there's no sort.

    As the context menu contains other options, I don't want to prevent the menu altogether. So is it something the user just has to put up with, or can those options be removed

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3331 posts

    Posted 23 Oct 2018 Link to this post

    Hello, Claire, 

    In order to hide a certain item from the context menu, you can handle the ContextMenuOpening event and hide the menu items for sorting as follows:
     
    private void radVirtualGrid1_ContextMenuOpening(object sender, VirtualGridContextMenuOpeningEventArgs e)
    {
        foreach (RadItem item in e.ContextMenu.Items)
        {
            if (item.Text.Contains("Sort"))
            {
                item.Visibility = ElementVisibility.Collapsed;
            }
        }
    }

    Should you have further questions please let me know.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Czeshirecat
    Czeshirecat avatar
    62 posts
    Member since:
    Jun 2016

    Posted 23 Oct 2018 Link to this post

    I'm having a problem with resizing columns if I use this code. The mouse is captured but not released.

    (I generate the instance in the mousedown event as I can't initialise earlier. )

     

  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3331 posts

    Posted 24 Oct 2018 Link to this post

    Hello, Claire, 

    I have attached my sample project. The columns resizing seems to work as expected on my end. Am I missing something? Could you please specify the exact steps how to reproduce the problem? Feel free to modify it in a way to reproduce the experienced issue and get back to me with it so I can investigate the precise case. Thank you in advance. 

    I am looking forward to your reply.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. Czeshirecat
    Czeshirecat avatar
    62 posts
    Member since:
    Jun 2016

    Posted 24 Oct 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hi Dess.

    Using your project. I set the following property so it was similar to my project.

    this.radVirtualGrid1.MasterViewInfo.AutoSizeColumnsMode = Telerik.WinControls.UI.VirtualGridAutoSizeColumnsMode.Fill;

    When using the splitter between columns[1] and columns[2]  to resize column[1] I find that releasing the mouse button doesn't cause the splitter to release, even when clicking on the grid. It seems to work ok once or twice but once it fails then keeps failing.

     

  8. Czeshirecat
    Czeshirecat avatar
    62 posts
    Member since:
    Jun 2016

    Posted 24 Oct 2018 Link to this post

    Ive stuck a video on youtube. Hope it works
    https://youtu.be/jyr8iQoge44
  9. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3331 posts

    Posted 24 Oct 2018 Link to this post

    Hello, Claire, 

    The provided sample video is greatly appreciated. It was very tricky and difficult to replicate the problem but I have succeeded to replicate it. I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

     I have also updated your Telerik points.

    Currently, the possible solution that I can suggest is to handle the MouseUp event and set the cursor to default.

    private void radVirtualGrid1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            this.radVirtualGrid1.Cursor = Cursors.Default;
        }
    }

    This seems to work on my end. Could you please give it a try and get back to us with the obtained result on your end? Thank you in advance.

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top