We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Detecting cell right mouse click on sfdatagrid

How can I detect a RIGHT mouseclick on a cell of sfdatagrid, and get the row and column number?

5 Replies

SA Saravanan Ayyanar Syncfusion Team January 2, 2020 01:01 PM UTC

Hi Tom,  
  
Thanks for using Syncfusion controls.  
  
You can able to detect the right mouse click of GridCell by using SfDataGrid.CellClick event. Please refer the below code snippet.  
  
this.sfDataGrid1.CellClick += SfDataGrid1_CellClick;  
  
private void SfDataGrid1_CellClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs e)  
{  
    if(e.MouseEventArgs.Button==MouseButtons.Right)  
    {  
        var rowColumnIndex =this.sfDataGrid1.TableControl.PointToCellRowColumnIndex(e.MouseEventArgs.Location);  
    }  
}  
  
  
Please find the sample below. 
  
Sample Link:  
  
Please let us know, if you require further assistance on this.  
  
Regards,  
Saravanan A.  



TK Tom Krieg January 3, 2020 04:11 AM UTC

Thanks for your reply. I am using Visual Basic and have the following code (derived from the C# code you provided and where gridReceipts is a sfdatagrid).

    Private Sub gridReceipts_CellClick(sender As Object, e As CellClickEventArgs) Handles gridReceipts.CellClick
        If e.MouseEventArgs.Button = MouseButtons.Right Then
            Dim rowColumnIndex = gridReceipts.TableControl.PointToCellRowColumnIndex(e.MouseEventArgs.Location)
        End If
    End Sub

I get the following error:  Option Strict On requires all variable declarations to have an 'As' clause

I cannot use the type 'RowColumnIndex' (as specified in your example for sfdatagrid online help) and if I do the compiler throws an error. (Type 'RowColumnIndex' is not defined.

Could you please advise what type I should use in the 'as' clause?

I have references to
 Syncfusion.WinForms.DataGrid
 Syncfusion.WinForms.DataGrid.Events
 Syncfusion.WinForms.ListView.Events



SA Saravanan Ayyanar Syncfusion Team January 3, 2020 07:37 AM UTC

Hi Tom,  
  
Thank you for update. 
 
We have analyzed your reported issue with provided code example. But the issue is not reproduced and  the sample is executed without any compiler error at our end. And you can use the type RowColumnIndex from the Syncfusion.WinForms.GridCommon.ScrollAxis namespace.  
  
Sample Link:  
  
If still you are facing the same issue, please revert us with more details on replication procedure/video illustration of the issue. Also if possible, please revert us with the modified sample. It will helps us to investigate further and provide earlier prompt solution.  
  
Regards,  
Saravanan A.  



TK Tom Krieg January 3, 2020 08:37 AM UTC

Once I referenced Syncfusion.WinForms.GridCommon.ScrollAxis then the errors disappeared and the function works as documented. Thanks.


FP Farjana Parveen Ayubb Syncfusion Team January 3, 2020 08:39 AM UTC

Hi Tom, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon