我創建上下文菜單dinamically並希望將菜單項分配給我自己的函數(帶參數)。不幸的是,不要按我的意願去。使用自定義函數dinamically添加context_menu項目
以下示例說明了我想要做的事情。
Private Sub dgv_sub_CellMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgv_sub.CellMouseUp
If e.Button = Windows.Forms.MouseButtons.Right Then
dgv_sub.Rows(e.RowIndex).Selected = True
context_sub.Items.Clear()
context_sub.Items.Add("Delete row " + dgv_sub.CurrentRow.Index.ToString, Nothing) AddressOf delRow(dgv_sub.CurrentRow.Index))
context_sub.Items.Add("Delete all rows", Nothing) , AddressOf delRow(-1))
context_sub.Show(New Point(Cursor.Position.X, Cursor.Position.Y))
End If
End Sub
Private Sub delRow(ByVal rowtodelete As Integer)
End Sub
如何正確設置並使其按照所述的方式工作?
你非常接近但是我不確定你是否真的需要這是動態的。你可以在之前添加這兩個項目並添加一個單擊事件,然後在'MouseDown'中設置你想要的可見性。讓我知道如果這沒有幫助 –
嗨基思。這裏還有其他未描述的功能,因爲在這個上下文菜單下的情況可能會有很大的不同。在這個例子中,我展示了足以描述我的需求的簡化版本。 – user1697111
好吧,我明白了,我會在幾分鐘後發佈我的答案:) –