iGrid - VB Grid Control

10Tec iGrid ActiveX is a top-notch VB grid control. It is built on the Visual Basic runtime library, which makes this component a native grid control for the VB6 IDE and Visual Basic for Applications in Microsoft Office:

VB grid control in VB6 IDE

iGrid ActiveX is a VB grid control allowing you to access its cells like items in a 2-dimensional array. What is important, every cell of iGrid can contain a value of the VB Variant data type. This allows you to mix values of various types in the same column with no additional efforts from your side.

The usage of this grid control in VB begins with definition of the rows and columns. In the simplest case, you can specify the required numbers of columns and rows with the ColCount and RowCount properties, and iGrid will create cells on intersections of these columns and rows automatically. After that you can set cell values with the CellValue property using the array syntax:

With iGrid1
   .ColCount = 5
   .RowCount = 10
   .CellValue(1, 1) = 100
   .CellValue(2, 1) = "Some text"
End With

The code above creates a VB grid with 5 columns and 10 rows and populates the top two cells in the first column with a number and string value:

VB grid control sample form

There is another way to create columns. You can define them one-by-one using the AddCol method, for example:

iGrid1.AddCol sHeader:="Company"
iGrid1.AddCol "id", "Person ID", 125

The first statement calls the AddCol method without parameters to create a column with default settings in a VB grid control named iGrid1. The next AddCol call specifies the column title text in the second created column. The last statement creates the third column and specifies the column's string key, title and width using the first 3 parameters of the AddCol method.

The AddCol method has more than a dozen optional parameters, and you can specify only the required parameters using named arguments or simply by separating them with commas. The same is true for the AddRow method used to create rows one-by-one and many other methods of iGrid. Almost all methods support optional parameters, and this simplifies the use of this grid control in VB and VBA.

Pay attention to the fact that you can optionally specify unique string keys for columns and rows as we did this for the Person ID column above. If a column or row has a key, you can use it instead of the numeric index to access this column/row in your VB code:

iGrid1.CellValue(100, "id") = 30056

This makes your code easily maintainable. Imagine a situation when you need to add a new column or remove existing one before a column with a specified key. You can continue access the cells in this column without adjusting the column numeric index in your code after every change in the column set of your VB grid control.

iGrid can be also populated with data from a DAO or ADO recordset with the FillFromRS method in one line of code. The data uploaded into this VB grid control can be formatted dynamically:

Dynamic data formatting in VB grid control

Dynamic data formatting is performed with events. You simply write an event handler for the corresponding event handler of the grid control as you could do this for any VB component. Below is the event handler for the RowDynamicFormatting event for the grid on the screenshot above:

Private Sub iGrid1_RowDynamicFormatting(ByVal lRow As Long, _
   oForeColor As Long, oBackColor As Long, oFont As StdFont)

   If iGrid1.CellValue(lRow, "Country") = "USA" Then
      oBackColor = RGB(224, 192, 224)
   End If

End Sub

iGrid provides you with a wide variety of events you can use from your VB code to adjust the behavior of this grid control and to get notifications about changes in it. These are events related to column movement and resizing, cell editing, mouse and keyboard operations, row grouping and so on.

The next pages in the Control Tour subsection allows you to find out more about this VB grid control.

Discover iGrid features in the Control Tour »