Hi!
On my Form there is a DataGridView that has a ContextMenuStrip bound to.
ContextMenuStrip has one button "Delete".
When I Right click on DataGridView then it displays the ContextMenuStrip, highlights entire row BUT the little arrow on the rowheader doesn't come along. That means if I click "Delete" button it will delete the row where this arrow is positioned.
Is there a way to get around this problem?
Here is my code for deleting:
Code:Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Try If Not DataGridView.CurrentRow.IsNewRow Then DataGridView.Rows.Remove(DataGridView.CurrentRow) Me.Validate() Me.BindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.DataSet) MsgBox("Row deleted successfully!", MsgBoxStyle.Information, "Database") End If Catch ex As Exception MsgBox("Row was not deleted (row not selected)", MsgBoxStyle.Information, "Database") End Try End Sub
And here is my DataGridView right click code:
P.S!Code:Private Sub DataGridView_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView.CellMouseDown If e.Button = Windows.Forms.MouseButtons.Right AndAlso e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0 Then DataGridView.ClearSelection() DataGridView.Rows.Item(e.RowIndex).Selected = True End If End Sub
Have tried with event cellmouseclick too...doesn't work.




Reply With Quote