For what you describe, the easiest way would be
if condition != TRUE
return
or
if condition == TRUE
{
}
else
return
If that doesn't fit what you want to do... please use the "improve question" widget and explain it more detailed
OP's last comment with self-made workaround added here for other people
Thanks so much. I have found a handle to my problem. I just put the code(messagebox and making the cell readonly)to execute when the condition is not met. Complete routine is shown below:
Private Sub DataGridView1_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
If (DataGridView1.CurrentCell.ColumnIndex = 12) Then
If (DataGridView1.CurrentRow.Cells("TransType").FormattedValue.ToString.ToUpper <> "E") AndAlso (DataGridView1.CurrentRow.Cells("TransType").FormattedValue.ToString.ToUpper <> "D") Then
Select Case e.Button
Case Windows.Forms.MouseButtons.Left
DataGridView1.CurrentCell.ReadOnly = True
MessageBox.Show("Editing this column is not allowed for this transaction", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
Case Windows.Forms.MouseButtons.Middle
DataGridView1.CurrentCell.ReadOnly = True
MessageBox.Show("Editing this column is not allowed for this transaction", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
Case Windows.Forms.MouseButtons.Right
DataGridView1.CurrentCell.ReadOnly = True
MessageBox.Show("Editing this column is not allowed for this transaction", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
Case Else
DataGridView1.CurrentCell.ReadOnly = False
End Select
Else
DataGridView1.CurrentCell.ReadOnly = False
End If
End If
End Sub
Thanks so much for your assistance