Determine Row and Cell where mouse right click was performed.

Hello Syncfusion team,

I need to know a row and a cell (if it is possible) on which I clicked with right mouse button. I found one similar question on the forum and it seems that before there was CellClick event for a grid component but it is no longer available. Were there any other way implemented to solve my problem?

Best regards,
Volodymyr

3 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team September 17, 2020 06:33 AM UTC

Hi Vladimir, 

Greetings from Syncfusion support. 

We have validated your query and you can use the ContextMenuOpen event of grid to achieve your requirement. On right mouse click, ContextMenuOpen event will be triggered when ContextMenuItems are defined in the grid. If you don’t want the context items to show in the grid, then define ContextMenuItems with empty list. Please refer the below code snippet and the sample for your reference. 

<SfGrid DataSource="@Orders" AllowPaging="true" ContextMenuItems="@(new List<ContextMenuItemModel>() { })"> 
<GridEvents  ContextMenuOpen="ContextMenuOpenHandler" CellSelected="CellSelected" TValue="Order" OnRecordClick="RecordClick"></GridEvents> 
.. 
.. 
</SfGrid> 
 
@code{ 
 
    public void ContextMenuOpenHandler(ContextMenuOpenEventArgs<Order> args) 
    { 
        Console.Write(args.RowInfo.CellIndex); 
        Console.Write(args.RowInfo.RowIndex); 
    } 
} 



Please get back to us if you need further assistance. 

Regards, 
Jeevakanth SP. 


Marked as answer

VM Vladimir Melnik September 18, 2020 11:03 AM UTC

Hi Jeevakanth,

solution which you've proposed is very helpful. But there is one issue which I have spotted. RowInfo.CellIndex doesn't work as I would expect. If I click in the grid row but not in one of the cells in the row CellIndex is set as an index of a nearest cell to the click position. In case when a row has a DetailTemplate and so collaps/expand button and i click on it then CellIndext keeps the last previous value. Is there any solution for this problem?

Best regards,
Volodymyr



JP Jeevakanth Palaniappan Syncfusion Team September 22, 2020 10:28 AM UTC

Hi Vladimir, 

We have validated your query and we are able to reproduce the reported issue at our end. So we have considered it as a bug and logged the defect report “Previous row/cell index maintained in ContextMenuOpen event” for the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our upcoming Patch release which is expected to be rolled out in the mid of October 2020. 
    
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.    


Until then we appreciate your patience. 

Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon