none
Control Items disappearing from ImageCombo control RRS feed

  • Question

  • I am attempting to put a drop down list of images within a word document. I figured I would do this with an ImageCombo control and just not put text next to the images. I set up an ImageList and an ImageCombo, changed the ImageCombo's properties so it would use my ImageList, and then used the following code to fill the ImageCombo.

    Private Sub Document_Open()
        Set ImageCombo1.ImageList = ImageList1
        With ImageCombo1
            .ComboItems.Clear
            .ComboItems.Add 1, "Im1", "1", 1
            .ComboItems.Add 2, "Im2", "2", 2
            .ComboItems.Add 3, "Im3", "3", 3
            .ComboItems.Add 4, "Im4", "4", 4
        End With
    End Sub

    I'm having two issues with this. The first is that when the code runs it doesn't put the images in the options, which defeats the purpose. The second is whenever I do something with the document, the options disappear and I am left with a once again empty Combobox. Am I doing something wrong? Is there a better place to put this code?

    I am a bit of a noob, so any help you can offer would be appreciated




    • Edited by Harlizonian Tuesday, March 7, 2017 11:28 PM
    Tuesday, March 7, 2017 10:49 PM

All replies

  • Hi Harlizonian,

    please use code below.

    Private Sub CommandButton1_Click()
    
         Dim imgLst As New ImageList
         Dim aObjName As Variant
         Dim aText As Variant
         Dim i As Long
    
         For i = 1 To 8
             imgLst.ListImages.Add _
             Key:="img" & i, _
             Picture:=LoadPicture("C:\Users\v-padee\Desktop\img1.jpg")
            
         Next
    
         Set ImageCombo1.ImageList = imgLst
         ImageCombo1.ComboItems.Clear
         For i = 1 To 7
             ImageCombo1.ComboItems.Add _
             Index:=i, _
             Text:="demo", _
             Image:="img" & i
             
         Next
    
         Set imgLst = Nothing
    
    End Sub

    Output:

    Reference:

    Using the ImageCombo Control

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 8, 2017 3:30 AM
    Moderator