Twin Basic User
2025-08-10T00:08:32Z
I'm trying to include a bmp image with the child node in a TREE GRID. I see it in the examples but I can't make it work. Here is my code and Access Database.

Regards

Mark

  MASTER_DB.zip (129kb) downloaded 6 time(s).

Private Sub Form_Load()
On Error GoTo ErrHandler
Debug.Print "Form_Load: Starting"

' 1. Open the database
Debug.Print "Form_Load: Checking database file"
If Dir("C:\Users\User\Documents\000_AUTOCAD_ELECTRICAL_TOOLS\000_LIB\009_MASTER_DATABASE\MASTER_DB.accdb") = "" Then
MsgBox "Database file not found!", vbCritical
Exit Sub
End If
Debug.Print "Form_Load: Opening connection"
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\User\Documents\000_AUTOCAD_ELECTRICAL_TOOLS\000_LIB\009_MASTER_DATABASE\MASTER_DB.accdb;"
If cnn.State <> adStateOpen Then
MsgBox "Failed to connect to database!", vbCritical
Exit Sub
End If
Debug.Print "Form_Load: Connection opened"

' 2. Open recordset and extract fields from SYMBOL table
Debug.Print "Form_Load: Opening recordset"
Dim sSQL As String
sSQL = "SELECT ID, SYMBOL_NAME, DIR_PATH FROM SYMBOL ORDER BY SYMBOL_NAME"
Set rs = New ADODB.Recordset
rs.Open sSQL, cnn, adOpenStatic, adLockReadOnly
If rs.EOF And rs.BOF Then
MsgBox "No records found in SYMBOL table!", vbInformation
rs.Close
Exit Sub
End If

' 3. Use iGrid30 for TREEGRID
With iGrid30
Debug.Print "Form_Load: BeginUpdate"
.BeginUpdate

' 4. Set columns (ID, SYMBOL_NAME, DIRECTORY, Image)
.ColCount = 4
.ColHeaderText(1) = "ID"
.ColHeaderText(2) = "SYMBOL_NAME"
.ColHeaderText(3) = "DIRECTORY"
.ColHeaderText(4) = "Image"

' Set tree column to 2 (SYMBOL_NAME)
.TreeCol = 2

' Optimize row height
On Error Resume Next
.DefaultRowHeight = .GetOptimalCellHeight(bCheckVisible:=True)
If Err.Number <> 0 Then
Debug.Print "Form_Load: GetOptimalCellHeight failed: " & Err.Number & " - " & Err.Description
.DefaultRowHeight = 20
Err.Clear
End If
On Error GoTo ErrHandler

' Load PNG into ImageList for child nodes
Debug.Print "Form_Load: Loading PNG"
LoadPicture Picture1, "C:\Users\User\Documents\000_AUTOCAD_ELECTRICAL_TOOLS\000_LIB\009_MASTER_DATABASE\portrait-lighting.png"
ImageList1.ListImages.Clear
ImageList1.ListImages.Add 1, "pngIcon", Picture1.Picture
.ImageList = ImageList1 ' Try .ImageListCells if images don't display

' 5. Add root node "ALARMS"
.AddRow
.CellValue(1, 2) = "ALARMS"
Dim rootRow As Long
rootRow = 1

' 6. Add child nodes from SYMBOL_NAME with image
Dim childRow As Long
While Not rs.EOF
.AddRow vRowParent:=rootRow
childRow = .RowCount
.CellValue(childRow, 1) = rs!id
.CellValue(childRow, 2) = rs!SYMBOL_NAME
.CellValue(childRow, 3) = rs!DIR_PATH
.CellIcon(childRow, 4) = 1 ' Assign PNG to image column
.CellAlignH(childRow, 4) = igAlignHCenter
.CellAlignV(childRow, 4) = igAlignVCenter
rs.MoveNext
Wend

' Auto-width columns
.AutoWidthCol 1
.AutoWidthCol 2
.AutoWidthCol 3
.AutoWidthCol 4

.EndUpdate
Debug.Print "Form_Load: EndUpdate"
End With

rs.Close
Set rs = Nothing
Exit Sub

ErrHandler:
MsgBox "Error in Form_Load: " & Err.Number & " - " & Err.Description, vbCritical
Debug.Print "Form_Load: Error: " & Err.Number & " - " & Err.Description
If Not rs Is Nothing Then
If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
If Not rs Is Nothing Then
If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
End If
If Not cnn Is Nothing Then
If cnn.State = adStateOpen Then cnn.Close
Set cnn = Nothing
End If
End Sub
Igor/10Tec
2025-08-11T08:34:18Z
When you ask a question about iGrid ActiveX, please, specify which edition (Classic or Modern) you are using and in which environment, including the bitness (32/64-bits). It's very important context that can help us to give you a correct answer.

As I understood, this question is about the Modern Editon of iGrid you use in Microsoft Access. And most likely, you are using the 64-bit iGrid in 64-bit Access. if so, then the key to answer is the absence of the 64-bit version of the ImageList OCX that can work in this environment together with iGrid. Unfortunately, twinBASIC still does not provide full backward compatibility with VB6, and we can't provide the 64-bit version of the vbAccelerator ImageList control that can work in 64-bit apps like Access.

We provide another way of using images in iGrid in such environments. If you install the iGrid demo, you will find ImageList samples based on the CImageList class that work in both 32-bit and 64-bit environments. We even already discussed the functionality of this class on this forum in the following thread:

https://10tec.com/forum/...ng-image-into-CImageList 

Try to use this code-only solution with iGrid. If you have any questions regarding this approach, feel free to ask us more.

Igor/10Tec
2025-11-19T15:27:47Z
64-bit 10Tec ImageList ActiveX was released yesterday. Now we have the ability to use the traditional approach with storing iGrid cell images in an ImageList control in 64-bit Office apps!