ContextMenu in new record

Hi! I want to enable a context menu when adding a new record to call a search form and select a value, but I can't activate the menu when I right click. I think maybe I should set the menu to the textbox cellrenderer but I don´t konw to do it


6 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team January 25, 2021 01:24 PM UTC

Hi Walter Ferrero,

Thank you for contacting Syncfusion support.


SfDataGrid provides an entirely customizable menu to expose the functionality on user interface by using ContextMenuStrip. It allows to create context menus for different rows in an efficient manner.

The context menu for the records can be set by using SfDataGrid.RecordContextMenu property.
For more information, please refer the below UG link, 
Can you please share us below things?       
        1. Brief replication procedure/video illustration of the reported issue
        2.
Could you please provide more details about your scenario with illustrations?
        3.
Provide the code snippet related customization in SfDataGrid

It will be helpful for us to check on it and provide you the solution at the earliest.

Regards,
Vijayarasan S
 



WF Walter Ferrero January 25, 2021 03:28 PM UTC

Hi! Thanks for the reply. I used the RecordContextMenu property, but it doesn't work when it's a new record. It works correctly when the record has data. I show below some code snippets: 

        public void InitGridActividades()
        {
            gridActividades.AllowDeleting = true;

            // enable the context menu to delete records
            gridActividades.RowHeaderContextMenu = new ContextMenuStrip();
            gridActividades.RowHeaderContextMenu.Items.Add("Borrar Fila", null, OnDeleteClicked);
            
             // enable the context menu for new records
            gridActividades.RecordContextMenu = new ContextMenuStrip();
            gridActividades.RecordContextMenu.Items.Add("Buscar", null, OnSearchClicked);
        }

         // call the search form
        private void OnSearchClicked(object sender, EventArgs e)
        {
            ISearchView ViewSearch = GetControllerSearchActividades().GetView();
            ViewSearch.Show();
        }

I also attach the following images:

  • Captura 1: grid initialization.
  • Captura 2: grid state after create new record.
  • Captura 3: grid state after right click on the new record.
  • Captura 4: grid state when right click on the record with data


Attachment: Syncfusion_efc0e15a.7z


VS Vijayarasan Sivanandham Syncfusion Team January 26, 2021 04:19 PM UTC

Hi Walter Ferrero,

Thanks for the update.

Currently, we are analyzing your requirement of “ContextMenu in new record in SfDataGrid”. We will validate and update you the details on or before January 28, 2021. 
 
We appreciate your patience until then. 
 
Regards, 
Vijayarasan S


VS Vijayarasan Sivanandham Syncfusion Team January 28, 2021 12:35 PM UTC

Hi Walter Ferrero,

Thank you for your patience.

By default SfDataGrid ContextMenu will not be showing in AddNewRow. You can achieve your requirement by customization the MouseUp event in sfDataGrid.TableControl. Please refer the below code snippet for your reference, 
sfDataGrid.TableControl.MouseUp += SfDataGrid_MouseUp; 
 
//Get the record context while AddingNewRow menu by customization  
private void SfDataGrid_MouseUp(object sender, MouseEventArgs e) 
{ 
            // get the row and column index based on the pointer position  
            var rowColIndex = sfDataGrid.TableControl.PointToCellRowColumnIndex(e.Location);          
 
            //Check the condition is AddNewRow and Only show the context menu while pressing right button of Mouse 
            if (e.Button == MouseButtons.Right && sfDataGrid.IsAddNewRowIndex(rowColIndex.RowIndex) && this.sfDataGrid.RecordContextMenu != null && !rowColIndex.IsEmpty) 
            { 
                ContextMenuStrip contextMenu = null; 
 
                //set the Record contextMenu for AddNewRow 
                contextMenu = this.sfDataGrid.RecordContextMenu; 
                //get the location  
                var location = this.sfDataGrid.TableControl.PointToScreen(e.Location); 
                if (contextMenu != null) 
                { 
                    //show the ContextMenu for AddNewRow 
                    contextMenu.Show(location);                     
                } 
            } 
} 
Please let us know, if you require further assistance on this. 
Regards,
Vijayarasan S 


Marked as answer

WF Walter Ferrero January 31, 2021 08:54 PM UTC

Hi! I checked your code sample and was able to fix my problem. Thank you for your help. Regards,


VS Vijayarasan Sivanandham Syncfusion Team February 1, 2021 12:46 PM UTC

Hi Walter Ferrero, 
 
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, 
Vijayarasan S 


Loader.
Up arrow icon