Trouble with ListImage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Stanton

    Trouble with ListImage

    Help

    I have a form where I am trying to load Icons to subsequently display in a
    Tree menu system. The following 2 bits of code are run on the OnOpen Event
    after clearing out the old images.
    The form has a MSComctlLib.Ima geListCtrl.2 control on it.
    The IconTable contains the name of the icon e.g. Folder_Open.ico and a
    number
    The 11 images were originally loaded "by hand"

    After running the initialize routine if I type ?
    ImList.Object.L istImages.Count in the immediate window I get as expected 0,
    but if I look at the ImList control, all 11 images are still there

    Function ImageList_Initi alize(ByVal ImageList As Object)

    On Error GoTo ImageList_Initi alize_Error

    ImageList.ListI mages.Clear

    ImageList_Initi alize_Error:
    If Err Then MsgBox Err.Description , vbCritical, "No." & Err.Number

    End Function

    If I manually delete the images, the following routine does not add them
    back

    Function ImageList_Fill( ByVal ImageList As Object, ByVal IconTableName As
    String) As Boolean

    On Error GoTo ImageList_Fill_ Error
    '* ImageList-Variablen definieren
    Dim img As ListImage
    '* DAO-Variablen definieren
    Dim MyDb As Database
    Dim IconTable As Recordset

    '* Funktion initialisieren
    ImageList_Fill = False

    ImList.Object.I mageWidth = 16
    ImList.Object.I mageHeight = 16
    '* DAO-Variablen initialisieren
    Set MyDb = CurrentDb()
    Set IconTable = MyDb.OpenRecord set(IconTableNa me, dbOpenDynaset)
    '* Wenn kein Datensatz vorhanden, dann Abbruch!
    If IconTable.Recor dCount = 0 Then GoTo ImageList_Fill_ Exit

    IconTable.MoveF irst
    While Not IconTable.EOF
    '* kleine Images in ImageList einfügen
    If Dir(CoIconPath & "\" & IconTable![IconName] & ".ico") "" Then
    ' Found
    Set img = ImageList.ListI mages.Add(IconT able![IconNo] + 1,
    IconTable![IconName], _
    LoadPicture(CoI conPath & "\" & IconTable![IconName] &
    ".ico"))
    End If
    IconTable.MoveN ext
    Debug.Print ImList.Object.L istImages.Count
    Wend

    '* Funktion erfolgreich!
    ImageList_Fill = True

    ImageList_Fill_ Exit:
    '* DAO-Variablen schliessen
    IconTable.Clone
    MyDb.Close
    '* DAO-Variablen terminieren
    Set IconTable = Nothing
    Set MyDb = Nothing

    ImageList_Fill_ Error:
    If Err Then MsgBox Err.Description , vbCritical, "No." & Err.Number

    End Function

    Can anyone point me in the right direction. It is a pain in the a.. loading
    the images by hand

    Many thanks

    Phil

    PS Sorry about the German. Can't remember where I nicked the original code
    from


Working...