VB Migration Partner

KNOWLEDGE BASE - Database and data-binding


Previous | Index | Next 

[PRB] The DataGrid’s SelColChange event may fire unexpectedly

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)
        '## InsertStatement If IsRecursiveMethodCall6() Then Exit Sub
        ' the remainder of the event handler here
        ' ...
    End Sub
Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.




Code Architects and its partners offers remote and onsite migration services.

More details




Subscribe to our free newsletter for useful VB6 migration tips and techniques.

newsletter



To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice



A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial




The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote




Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers