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

Right click but disable SelectionChanged

1 Answer 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shakti SIngh Dulawat
Top achievements
Rank 1
Shakti SIngh Dulawat asked on 19 Jul 2016, 11:02 AM

Dear Friends,
I am using telerik SelectionChanged event to select row value from grid, another thing I am opening context menu using ContextMenuOpening event, now the problem I am facing is that when I do right click I loss my current selected row.
I do not want to loss current selected row but same time I want to fire  right click event using ContextMenuOpening , do we have any possible solutions for it so we will not loss our selected row when firing ContextMenuOpening of grid.

 

Thanks

Shubham
Top achievements
Rank 3
Iron
Iron
Iron
commented on 20 Dec 2023, 10:45 AM

I  also need same thing is any answer available @Telerik

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 21 Dec 2023, 11:12 AM

Hello, Shubham,

SelectionChanged event triggers when the current selection has changed. On the other hand, showing the context menu is associated with a cell. That is why when using the mouse down, the cell under the cursor will get selected and then show the context menu. Thus, the SelectionChanged event is fired. 

If I understand you correctly, following the information provided in this post, you would not like to change the selection when right click with the mouse. If this is your requirement you can create a custom RadGridView and override its OnMouseDown event:

public class CustomGrid : RadGridView
{
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadGridView).FullName;
        }
    }

    protected override void OnMouseDown(MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            GridCellElement cellUnderMouse = this.ElementTree.GetElementAtPoint(e.Location) as GridCellElement;
            if (cellUnderMouse != null)
            {
                this.GridViewElement.ContextMenuManager.ShowContextMenu(cellUnderMouse);
            }

            return;
        }
        base.OnMouseDown(e);
    }
}

In case this is not the exact case that you have, it would be greatly appreciated if you provide more information about the desired behavior. 

I hope this helps. Please let me know if I can assist you further.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Shakti SIngh Dulawat
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or