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

Spreadsheet ActiveGrid.CellContextMenuOpening not firing event on spreadsheet

I'm working on customizing Context menu on spreadsheet and it appears to work ok on sample but when using on spreadsheet in application it doesnt appear to be firing the event.   

I copy/pasted a copy of the spreadsheet on the same form and added a second event handler for this copied spreadsheet and the context menu was being displayed correctly. 

I'm not sure on why the event is not firing on the 1st .

Added repro project  

Attachment: CommonLibrary_e636481e.zip

4 Replies

SP Spotty January 24, 2019 06:10 PM UTC

Added a better simpler repro.


1. Create a windows form application
2. add a button and spreadsheet and add the following code.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Spreadsheet1.Open("ManifestLoadOrder2019-01-24.xlsx")
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddHandler Spreadsheet1.ActiveGrid.CellContextMenuOpening, AddressOf ActiveGrid_CellContextMenuOpening
        Spreadsheet1.IsCustomTabItemContextMenuEnabled = False
    End Sub

    Private Sub ActiveGrid_CellContextMenuOpening(sender As Object, e As CellContextMenuOpeningEventArgs)
        'MessageBox.Show("Fired")
        Try
            If Spreadsheet1.ActiveGrid.CellContextMenu.Items.ContainsKey("PasteSpecial") = False Then
                '//Adding Customized Menu item
                Dim PasteSpecial = New ToolStripMenuItem() With {.BackColor = Color.White, .Name = "PasteSpecial"}
                PasteSpecial.Text = "PasteSpecial"
                AddHandler PasteSpecial.Click, AddressOf PasteSpecial_Click
                Spreadsheet1.ActiveGrid.CellContextMenu.Items.Add(PasteSpecial)

            End If

            If Spreadsheet1.ActiveGrid.CellContextMenu.Items.ContainsKey("InsertCommentMenuItem") Then
                Spreadsheet1.ActiveGrid.CellContextMenu.Items("InsertCommentMenuItem").Visible = False
            End If

        Catch ex As Exception

        End Try
        Spreadsheet1.ActiveGrid.Refresh()
    End Sub

    Private Sub PasteSpecial_Click(sender As Object, e As EventArgs)
    End Sub


2. Start application and Right click a cell to display context menu.  (Displays a context menu with Insert Comment hidden and PasteSpecial Visible.) or if you comment the msgbox you will see the event fires.
3. Click button to load spreadsheet (attached spreadsheet included - you may need to modify the path)
4. Right click a cell to display context menu.  Normal context menu is visible with event not firing.

ACTUAL RESULT
After loading spreadsheet - context menu event does not fire

EXPECTED RESULT
After loading spreadsheet - context menu event firing




Attachment: ManifestLoadOrder20190124_49795f81.zip


AA Arulraj A Syncfusion Team January 25, 2019 06:06 AM UTC

Hi Spotty, 

Thanks for your update. 

In your provided code part, you have triggered the CellContextMenuOpening event in Form.Load event. This Load event will be triggered at initially. If you importing the excel file using button it will be acted like a separate grid. So, you need to trigger the CellContextMenuOpening event for that grid. So, you could use the CellContextMenuOpening event in WorkbookLoaded event. Please refer the following code example. 

VB 
AddHandler ManifestSpreadsheet1a.WorkbookLoaded, AddressOf SetupWorksheet 
Private Sub SetupWorksheet(sender As Object, args As WorkbookLoadedEventArgs) 
    AddHandler ManifestSpreadsheet1.ActiveGrid.CellContextMenuOpening, AddressOf ActiveGrid_CellContextMenuOpening 
    PopulateColorsFromSpreadsheet() 
End Sub 

Please get back us if you need any further assistance on this, 

Regards,   
Arulraj A 



SP Spotty January 25, 2019 05:18 PM UTC

Interesting....  

So if I'm understanding this correctly I need to setup the context events after each spreadsheet is loaded, rather than once at the start for the control.  

Seems a little strange and perhaps should be more prominently documented.



AA Arulraj A Syncfusion Team January 28, 2019 12:34 PM UTC

Hi Spotty, 

 

Thanks for your suggestion.

 

We have considered your feedback. We have logged the documentation report for this. It will be available in our upcoming release 2018 Volume SP1 which is expected to roll out in the first week of February 2019.

 

Regards,

Arulraj A



Loader.
Live Chat Icon For mobile
Up arrow icon