Hi @Mansour_Dalir ,
You can move the focus to other control before setting the DataGridView's AllowUserToAddRows property.
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
Button1.Focus()
DataGridView1.AllowUserToAddRows = Not DataGridView1.AllowUserToAddRows
End Sub
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.