SpreadSheetGear右键单击Vb.Net中的菜单编辑

时间:2014-10-16 07:05:44

标签: vb.net excel winforms ms-office spreadsheetgear

我是否可以:在SpreatSheetGear中编辑Sheet的选定单元格的右键菜单以添加Merge等选项,然后处理选择该菜单项的事件? 在此先感谢分享一些想法。

1 个答案:

答案 0 :(得分:1)

您应该只能将ToolStripItem添加到WorkbookView.ContextMenuStripContextMenuStrip属性继承自Control类):

' Create and add new item to WorkbookView's context menu
Dim newItem As ToolStripItem = workbookView.ContextMenuStrip.Items.Add("Merge Cells")

' Add event handler
AddHandler newItem.Click, AddressOf MenuItemMergeCells_Click

...

Private Sub MenuItemMergeCells_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim item As ToolStripItem = CType(sender, ToolStripItem)
    If item.Text = "Merge Cells" Then
        workbookView.GetLock()
        Try
            ' Merging is only valid for multi-cell ranges
            If workbookView.RangeSelection.CellCount >= 2 Then
                workbookView.RangeSelection.Merge()
            End If
        Finally
            workbookView.ReleaseLock()
        End Try
    End If
End Sub