We have noticed that the DataGrid ActiveX control may trigger spurious SelColChange events when it is used in a converted VB.NET application. For example, such an event is fired if the DataGrid is bound to an ADO data source, the code invokes a MoveXxxx method on the bound recordset, and the method has no effect – such as a MoveFirst method on a recordset whose first record is already the current record. In VB6 no event is fired in such circumstances.
Unfortunately, there is no easy way to force the VB.NET version of the DataGrid control to behave exactly like the original VB6 control. In most cases, the spurious event adds a little overhead but doesn’t otherwise alter the application’s behavior.
You have a problem, however, if the code in the handler of the SelColChange event directly or indirectly invokes a MoveXxxx method, because the VB.NET application might be trapped in an endless loop and eventually throw a StackOverflow exception.
If you experience such a runtime error, you have to protect the code from recursion. The simplest way to do so is by means of the IsRecursiveMethodCall6 method defined in the support library. This method returns True if the calling method – that is, the method that is calling IsRecursiveMethodCall6 – has invoked itself recursively, either directly or indirectly. Therefore, you can protect from recursive SelColChange events using this code:
Private Sub DataGrid_RowColChange(ByRef LastRow As Object, ByVal LastCol As Short)