Previous | Index | Next 

[PRB] Code that references a VB6DataGrid column by its string key may not work in the migrated VB.NET program

Columns in a VB6 DataGrid control can be referenced by either their numeric index or their string key. (The string key is equal to the column’s Caption property.)

This mechanism works correctly with the VB6DataGrid control in converted VB.NET programs. However, we have noticed that assigning a reference to an ADO Data control to the DataSource property causes the control to recreat the Columns collection so that their captions match the fields’ names exactly. (The same thing happens when you assign a DataEnvironment object or an ADO Recordset.)

For this reason, if the VB6 application uses column captions that are different from field names – as it is often the case – then indexing the Columns collection by a string key can’t work correctly after the migration to VB.NET. The simplest workaround for this issue is to manually restore columns’ caption (and therefore, column keys) in the Form_Load event handler, as in this code:

    DataGrid1.Columns(0).Caption = "Supplier"   ' instead of "SupplierID"
    DataGrid1.Columns(1).Caption = "Category"   ' instead of "Category"


Previous | Index | Next