VB6 DataGrid Control Alternative

Edited by

VB6 DataGrid control problems

The VB6 DataGrid control shipped with Visual Basic 6 does its main work, i.e. displays ADO Recordsets, good enough. But if you want to make its data rows more user-friendly (say, color cells based on some conditions), VB6 DataGrid provides you with no helpful tools for that. Our company provides a similar VB6 grid control named iGrid that can be used as an excellent alternative to VB6 DataGrid:

Sample form with VB6 DataGrid control (MSDatGrd.OCX) alternative

As you can see from this screenshot, iGrid surpasses VB6 DataGrid in the following functionality:

  1. You can format cells with colors and fonts.

  2. You can sort DataGrid just by clicking its column headers.

  3. DataGrid does not implement checkbox and combobox cell editors, but iGrid does.

  4. Cell text can be multiline and/or use other formatting options.

  5. iGrid has a very rich set of events to control the user's activity.

VB6 DataGrid Column Formatting

The VB6 DataGrid control provides you with the ability to use the StdDataFormat object to format its columns dynamically - see, for instance, the following resource:

VB6 Datagrid Column Formatting

If you used this approach, you already know that StdDataFormat is defined in a separate DLL, MSSTDFMT.DLL, but not in the DataGrid OCX file MSDATGRD.OCX. So you need to redistribute one more library with your end-user app and register it on client computers to make the whole system work.

Another restriction of this way of formatting is that it can be applied only to the whole column. iGrid has a similar tool (cell format strings), but it also gives you much more control over the look of individual cells or rows with the dynamic formatting events CellDynamicFormatting or RowDynamicFormatting. Here is an example in which we highlight cells with values greater than or equal to 50'000 with the red color in the Sum column:

Private Sub iGrid1_CellDynamicFormatting( _
     ByVal lRow As Long, ByVal lCol As Long, _
     ByVal vValue As Variant, _
     oForeColor As Long, oBackColor As Long, _
     oFont As StdFont)
 
   If iGrid1.ColKey(lCol) = "sum" Then
      If vValue >= 50000 Then
         oForeColor = vbRed
      End If
   End If
 
End Sub

As you can see from the event signature, you can change the text color, background color and even font for any cell or the whole row in one event handler on-the-fly.

MSDATGRD.OCX not registered problem in Windows 7/10

The VB6 DataGrid control is an ActiveX control implemented in the MSDATGRD.OCX file. When you deploy your application to client computers, you also need to redistribute and register MSDATGRD.OCX in Windows 7 or 10 properly to avoid the MSDATGRD.OCX Not Registered error. As you already know from the previous subsection, VB6 DataGrid requires some extra files for proper functioning. These are COMCAT.DLL and MSSTDFMT.DLL, which must be deployed and registered with MSDATGRD.OCX too. And you should do it the right way to register MSDATGRD.OCX in 64-bit Windows 7 or 10:

MSDATGRD.OCX problem in Windows 10 from Outlook form 2016 with VBA

From this point of view, the iGrid control is a better VB6 DataGrid control alternative as it is implemented in one OCX file with no external dependencies.

Unbound VB6 grid control

VB6 DataGrid allows you to upload data from a database table or query, but in many cases you also need to display data stored not in a database (in a CSV file, an array, etc). In other words, you need an unbound VB6 DataGrid. If you decide to solve this task with the VB6 DataGrid control, first you need to load the data into a temporary interim data store and only after that bind the DataGrid to it to show your data on the screen.

But this is just a half of the problem: you cannot freely change or format your data in individual cells as they are in fact the underlying recordset fields. And this is really annoying if you need data of different data types and/or formatting in the same column.

iGrid is free from all the drawbacks mentioned above. Unbound mode, when you can change its cell independently, is its main work mode. In addition to this, iGrid allows you to upload ADO and DAO Recordsets into it with one command and use all its rich formatting features for these data without any restrictions.

Versatile data binding

Despite the fact that iGrid works mainly in unbound mode, you can make it a data-bound control by adding some code. A big benefit of this approach is the ability to control all aspects of the functionality - you will never get such a level of control in DataGrid.

The main demo of iGrid contains a series of samples demonstrating different approaches of data binding you can implement with iGrid. You can cache the user changes on the field-, row- or entire grid-level, or you can store your edited data in an ADODB Recordset or retrieve and update them directly through an ADODB Connection object. This is ready-to-use code you can use in your apps for free, and (what is most important!) change the functionality in every particular scenario to fully suit your users' needs.

Add to this the modern look-n-feel based on the visual styles from the latest versions of the Windows OS, such as Windows 7 and Windows 10, and you get an excellent replacement for the VB6 DataGrid control!

Discover more advantages of the iGrid OCX grid control »