我是否可以:在SpreatSheetGear中编辑Sheet的选定单元格的右键菜单以添加Merge等选项,然后处理选择该菜单项的事件? 在此先感谢分享一些想法。
答案 0 :(得分:1)
您应该只能将ToolStripItem添加到WorkbookView.ContextMenuStrip
(ContextMenuStrip属性继承自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