I currently have a DatagridView and when I right click on a cell, i want a menu strip to appear with the option to Insert Row & Delete Row.
The code below achieves this (display of the menu strip items ,Insert Row & Delete Row)
however when you click on one of the items, i can not get the handler to work -
The error being in the handler
saying a handles clause required
The code below achieves this (display of the menu strip items ,Insert Row & Delete Row)
however when you click on one of the items, i can not get the handler to work -
The error being in the handler
Code:
Private Sub contextMenuDataGrid_Click(sender As Object, e As EventArgs) Handles contextMenuDataGrid.Click
Code:
ublic Class Form1
Dim index As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DbTestDataSet.Staff' table. You can move, or remove it, as needed.
Me.StaffTableAdapter.Fill(Me.DbTestDataSet.Staff)
End Sub
Private Sub DataGridView1_CellMouseDown(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDown
If e.Button = MouseButtons.Right Then
DataGridView1.CurrentCell = DataGridView1(e.ColumnIndex, e.RowIndex)
Dim contextMenuDataGrid As New ContextMenuStrip
contextMenuDataGrid.Items.Add("Insert Row")
contextMenuDataGrid.Items.Add("Delete Row")
contextMenuDataGrid.Show(DataGridView1, e.Location)
' MsgBox("Hello")
End If
End Sub
Private Sub contextMenuDataGrid_Click(sender As Object, e As EventArgs) Handles contextMenuDataGrid.Click -<------------ERROR ContextMenuDataGrid.Click -
MsgBox("QQ")
If Not DataGridView1.Rows(index).IsNewRow Then 'CHECK IF NEW ROW
DataGridView1.Rows.RemoveAt(index)
End If