怎样动态触发ToolStripMenuItem菜单的点击事件
1个回答
2015-01-26 · 知道合伙人互联网行家
关注
展开全部
#Region "DataGridView右键菜单"
Public Sub SetContextMenuStrip()
Dim ToolStripMenuItem1 As New System.Windows.Forms.ToolStripMenuItem("查找定位")
Dim ToolStripMenuItem2 As New System.Windows.Forms.ToolStripMenuItem("记录范围筛选")
Dim ToolStripMenuItem3 As New System.Windows.Forms.ToolStripMenuItem("固定列")
Dim ToolStripMenuItem4 As New System.Windows.Forms.ToolStripMenuItem("多列排序")
Dim ContextMenuStrip1 As New ContextMenuStrip
MyGrid.ContextMenuStrip = ContextMenuStrip1
With ContextMenuStrip1.Items
.Add(ToolStripMenuItem1)
.Add(ToolStripMenuItem2)
.Add(ToolStripMenuItem3)
End With
AddHandler ToolStripMenuItem1.Click, AddressOf ToolStripMenuItem_Click
AddHandler ToolStripMenuItem2.Click, AddressOf ToolStripMenuItem_Click
AddHandler ToolStripMenuItem3.Click, AddressOf ToolStripMenuItem_Click
End Sub
Private Sub ToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case sender.text
Case "查找定位"
Me.ShowGridFind()
Case "记录范围筛选"
Me.ShowGridFilter()
Case "固定列"
Me.ShowGridColumn(ColumnProperty.固定列)
End Select
End Sub
#End Region
Public Sub SetContextMenuStrip()
Dim ToolStripMenuItem1 As New System.Windows.Forms.ToolStripMenuItem("查找定位")
Dim ToolStripMenuItem2 As New System.Windows.Forms.ToolStripMenuItem("记录范围筛选")
Dim ToolStripMenuItem3 As New System.Windows.Forms.ToolStripMenuItem("固定列")
Dim ToolStripMenuItem4 As New System.Windows.Forms.ToolStripMenuItem("多列排序")
Dim ContextMenuStrip1 As New ContextMenuStrip
MyGrid.ContextMenuStrip = ContextMenuStrip1
With ContextMenuStrip1.Items
.Add(ToolStripMenuItem1)
.Add(ToolStripMenuItem2)
.Add(ToolStripMenuItem3)
End With
AddHandler ToolStripMenuItem1.Click, AddressOf ToolStripMenuItem_Click
AddHandler ToolStripMenuItem2.Click, AddressOf ToolStripMenuItem_Click
AddHandler ToolStripMenuItem3.Click, AddressOf ToolStripMenuItem_Click
End Sub
Private Sub ToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case sender.text
Case "查找定位"
Me.ShowGridFind()
Case "记录范围筛选"
Me.ShowGridFilter()
Case "固定列"
Me.ShowGridColumn(ColumnProperty.固定列)
End Select
End Sub
#End Region
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询