datagridview的mousedown事件我已經寫在VS.NET的Visual Basic在Visual Studio中的應用程序2005.NET Windows窗體不觸發
它具有Windows窗體,具有DataGridView
控制它來顯示從檢索到的數據數據庫。
我想允許用戶右鍵單擊某個記錄,查看上下文菜單,並且可以單擊刪除從數據庫中刪除該記錄。
不幸的是我甚至不能按下鼠標或點擊事件火災(在調試模式下,設置斷點)
這裏是我的代碼:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
MessageBox.Show("You right-clicked on the grid at", "Unpaid", MessageBoxButtons.OK)
End Sub
Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
MessageBox.Show("You right-clicked on the grid at", "Unpaid", MessageBoxButtons.OK)
End Sub
Private Sub DataGridView1_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
MessageBox.Show("Clicked right")
else
MessageBox.Show("Clicked left")
End If
Dim r As Rectangle
if (e.RowIndex >= 0 && e.ColumnIndex >= 0 && e.Button == MouseButtons.Right)
DataGridView1.Rows(e.RowIndex).Selected = True
r = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True)
contextMnu.Show(DataGridView1, r.Left + e.X, r.Top + e.Y)
End If
End Sub
Private Sub DeleteChequeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteChequeToolStripMenuItem.Click
MessageBox.Show("You right-clicked on the grid", "Unpaid", MessageBoxButtons.OK)
End Sub
正如你所看到的,我我試圖獲得一些事件,任何事件觸發,並且當我右鍵單擊或甚至左鍵單擊時,沒有任何代碼正在運行。
BTW,有在運行時在網格中的數據,而據我所知,它被啓用
那我錯在這裏做什麼?是否有一些功能需要添加到DataGridView
控件中?
可以我的調試問題與窗體父(MDI窗體稱爲MDI子)相關? – 2013-02-25 16:04:10
啊,你應該在第一盤中提到這一點。如果「處理」不在事件調用的位置,我注意到有相同的問題。我建議刪除所有的事件,並嘗試從Child表單GUI事件添加器添加事件cellmousedown。然後在事件後鍵入「Handles」,查看intellisense帶來的選擇。我選擇了DataGridView1.CellMouseDown。然後事件似乎正常開火。 –
Patratacus
2013-02-25 16:32:34
另外,你是否設置子窗體使用主窗體作爲父窗體?像這樣的父母形式: FormChild.MdiParent = Me – Patratacus 2013-02-25 16:37:55