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

Passing parameters to RecordContextMenu

I am trying to use the sfDatagrid.Record contextMenu, but can't figure out how to add a function to the selected context menu. What I want is to pass the row index and column index into the Addcomment function, but am not sure what parameters should the RecordContextMenu take. Any help would be appreciated.

       ContextMenuStrip recordContextMenu = new ContextMenuStrip();
       recordContextMenu.Items.Add("Add Comment", null, AddComment);
       sfDataGrid4.RecordContextMenu = recordContextMenu;

        private void AddComment(int rowIndex, int colIndex)
        {
            form2 f1 = new form2(columnIndex, ID);
            f1.ShowDialog();
        }

1 Reply

JP Jagadeesan Pichaimuthu Syncfusion Team April 1, 2019 11:59 AM UTC

Hi Julius,  

Thank you for contacting Synfusion Support. 

We have analyzed your query to pass row and column index in contextmenu function and you can achieve this by retrieving row and column index from the current cell by using the below code snippet. 

ContextMenuStrip recordContextMenu = new ContextMenuStrip(); 
recordContextMenu.Items.Add("Add Comment", null, AddComment); 
sfDataGrid4.RecordContextMenu = recordContextMenu; 
 
private void AddComment(object sender, EventArgs e) 
{ 
    var rowIndex = sfDataGrid4.CurrentCell.RowIndex; 
    var columnIndex = sfDataGrid4.CurrentCell.ColumnIndex;     
    form2 f1 = new form2(columnIndex, ID);  
    f1.ShowDialog(); 
} 

Also please refer to the below UG link for more details on ContextMenu in SfDataGrid 


Please let us know, if you need any further assistance on this. 

Regards, 
Jagadeesan

Loader.
Live Chat Icon For mobile
Up arrow icon