VB.net disable DataGridVidew cell change triggering others

Murray Brown
Murray Brown used Ask the Experts™
Hi. During the event DataGridView2_CellValueChanged, I have code that changed all
other cells in the same row, but I want to disable  those changes rerunning this event.
In Excel VBA I know its   Application.EnableEvents = False but what would it be here
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

You may not be able to completely dis-able the event from re-running, but you can stop the rest of the code from running by adding a column filter, e.g if you only want to run the code when the first column changes
If CType(sender, DataGridView).CurrentCell.ColumnIndex = 0 Then
  'here run your code
End If

Open in new window

Most Valuable Expert 2012
Top Expert 2014
You can declare a class level flag

Dim AlreadyRunning As Boolean = False

private sub CellValueChanged(...)
 If Not AlreadyRunning Then
     AlreadyRunning = True
     'Rest of code
     AlreadyRunning = False
 End If
End Sub
Murray BrownASP.net/VBA/VSTO Developer


Great. Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial