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

Disabling sort on individual columns. How?

8 Answers 177 Views
VirtualGrid
This is a migrated thread and some comments may be shown as answers.
Czeshirecat
Top achievements
Rank 2
Iron
Iron
Czeshirecat asked on 22 Oct 2018, 11:25 AM

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)

8 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Oct 2018, 01:53 PM
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.
0
Czeshirecat
Top achievements
Rank 2
Iron
Iron
answered on 23 Oct 2018, 01:34 PM

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

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Oct 2018, 01:54 PM
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.
0
Czeshirecat
Top achievements
Rank 2
Iron
Iron
answered on 23 Oct 2018, 02:02 PM

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. )

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Oct 2018, 07:27 AM
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.
0
Czeshirecat
Top achievements
Rank 2
Iron
Iron
answered on 24 Oct 2018, 10:38 AM

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.

 

0
Czeshirecat
Top achievements
Rank 2
Iron
Iron
answered on 24 Oct 2018, 10:50 AM
Ive stuck a video on youtube. Hope it works
https://youtu.be/jyr8iQoge44
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Oct 2018, 02:04 PM
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.
Tags
VirtualGrid
Asked by
Czeshirecat
Top achievements
Rank 2
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Czeshirecat
Top achievements
Rank 2
Iron
Iron
Share this question
or