ImageList, ImageCombo and TabControl problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Breixo
    New Member
    • Dec 2014
    • 11

    ImageList, ImageCombo and TabControl problems

    Hi to all,

    I had a giant form with lots of controls "ImageList" located in its header and the corresponding controls "ImageCombo " in the detail of the form.
    The "ImageList" and "ImageCombo " controls were initialized and are loaded in the "Form_Load" event.
    The form is not linked, yet, with a database.

    I changed the giant form to a smaller one with a "TabControl " with four pages.
    I used the method of cut and copy controls.
    The "ImageList" controls remain at the form header.
    One of the controls "ImageCombo " is in the form header.

    Now, when I run the form, all controls "ImageCombo " appear without images or text except that remains in the header.

    I have tried to initialize and load the "ImageList" and "ImageCombo s" within each page of the "TabControl ", but when I switch the page and come back, all "ImageCombo " are empties.

    I searched internet solutions and examples and I guess the error is in how to identify each control in the field of each page, but I failed in all my tests.

    Can anyone help me, please?
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Breixo, It would be better if you showed some things you've already tried. Hard to know if how to help you. But I'll start with pointing you to this page. I think your problem is how to reference objects on a tab within a tab control. https://msdn.microsoft.com/en-us/lib...ffice.12).aspx

    Jim

    Comment

    • Breixo
      New Member
      • Dec 2014
      • 11

      #3
      Hi, jimatqsi,

      Thanks for your answer and your time. First of all, I am a beginner and I replace my shortcomings based on hours of searching for solutions on the internet and hours of trial and error and I just turn to this forum when I'm definitely stuck.

      Indeed, I had already read the linked page, again and again, but I have it clear that I have not been able to understand the strange bond between "ImageList" and "ImageCombo " controls when placed on a "TabControl ".

      I include my little test program and a graphical view of what is happening to me.

      I appreciate all the help you can provide me.

      Thanks again and best regards,
      Attached Files

      Comment

      • Breixo
        New Member
        • Dec 2014
        • 11

        #4
        Hi,

        Really nobody can help me?

        If I'm making a big mistake, please let me know, I'm absolutely stuck, not knowing what to do or where to go.

        Thanks for your time,

        Comment

        • jforbes
          Recognized Expert Top Contributor
          • Aug 2014
          • 1107

          #5
          OK, this thing is a mess. These are VB6 era controls. You probably should attempt to replace them with an alternative solution as soon as you can convince your customer/users of doing this a different way.

          I'm not sure if the control is being destroyed or just the handle to it is being lost, but either way, when the tabControl shows a different tab, the properties for the ImageCombo are lost. So to fix this, the control needs to be re-initialized and the selected item needs to be reselected whenever a different tab is shown to the user.

          First thing is to save off the Value of the ImageCombo so that it can be reset later. It looks like the .Tag property was being used before, so I reused it. VB6 loved the .Tag property.:
          Code:
          Private Sub ImageCombo01_Exit(Cancel As Integer)
              ImageCombo01.Tag = ImageCombo01.SelectedItem
          End Sub
          You might be able to save off the .Index, to speed things up, but I got this working and stopped there.

          Next, tweak the initialize routine for the ImageCombo, so that it reselects the value:
          Code:
          Public Function setImageCombo01Selection()
              If ImageCombo01.Tag = Null Then
                  ImageCombo01.Tag = 1
              ElseIf Len(ImageCombo01.Tag) > 0 Then
                  ' Find the Previously Selected Item
                  For Each oItem In ImageCombo01.ComboItems
                      If oItem = ImageCombo01.Tag Then ImageCombo01.SelectedItem = oItem
                      Exit For
                  Next oItem
              Else
                  ' Select the default item.
                  Set ImageCombo01.SelectedItem = ImageCombo01.ComboItems(3)
              End If
          End Function
          Lastly, reinitialize the ImageList and ImageCombo when the Tab is changed:
          Code:
          Private Sub tabControl01_Change()
              Select Case Me.tabControl01.Value
                  Case 0
                      Call Load_ImageList01
                      Call Load_ImageCombo01
                  Case 1
                      Call Load_ImageList02
                      Call Load_ImageCombo02
              End Select
          End Sub
          This could be much prettier, but I'll leave that up to you.

          Good luck.
          Last edited by jforbes; Feb 19 '15, 02:45 PM. Reason: typo

          Comment

          • Breixo
            New Member
            • Dec 2014
            • 11

            #6
            Thanks, jforbes, but I've been testing and combinations throughout the weekend and I've just gotten me out errors such as "The key is not unique" and others.

            I dare to abuse your time asking you to put me in my code should go where and how the routines that you have enclosed me.

            Forgive my boldness but I have two weeks without knowing how to solve this problem.

            Thanks again,

            Comment

            • jforbes
              Recognized Expert Top Contributor
              • Aug 2014
              • 1107

              #7
              I opened the program back up to copy and paste the code in it's entirety, and found an error. What a surprise. =) I screwed up the For Each Loop.

              Anyway, here is the whole code of what I got working:
              Code:
              Option Compare Database
              
              Private Sub Form_Load()
                  Call load_ImageList00
                  Call Load_ImageList01
                  Call Load_ImageList02
                  
                  Call Load_ImageCombo00
                  Call Load_ImageCombo01
                  Call Load_ImageCombo02
              
              End Sub
              ' LOCATED ON FORM HEADER
              Public Function load_ImageList00()
              ImageList00.ListImages.Add , "Zone 6 (-23 to -18ºC", LoadPicture(GetIconsPath & "IconsTest\zone06.ico")
              ImageList00.ListImages.Add , "Zone 7 (-18 to -12ºC)", LoadPicture(GetIconsPath & "IconsTest\zone07.ico")
              ImageList00.ListImages.Add , "Zone 8 (-12 to -7ºC)", LoadPicture(GetIconsPath & "IconsTest\zone08.ico")
              ImageList00.ListImages.Add , "Zone 9 (-7 to -1ºC)", LoadPicture(GetIconsPath & "IconsTest\zone09.ico")
              End Function
              
              Public Function Load_ImageCombo00()
              With ImageCombo00.ComboItems
                  .Add Text:="Zone 6 (-23 to -18ºC)", Image:=1
                  .Add Text:="Zone 7 (-18 to -12ºC)", Image:=2
                  .Add Text:="Zone 8 (-12 to -7ºC)", Image:=3
                  .Add Text:="Zone 9 (-7 to -1ºC)", Image:=4
              End With
              If ImageCombo00.Tag = Null Then
                  icbZones.Tag = 1
              Else
                 ' Select the default item. Zone 8
                  Set ImageCombo00.SelectedItem = ImageCombo00.ComboItems(3)
              End If
              End Function
              
              ' LOCATED ON FORM DETAIL, tabControl01, Page01
              Public Function Load_ImageList01()
              ImageList01.ListImages.Clear
              ImageList01.ListImages.Add , "Unknown", LoadPicture(GetIconsPath & "IconsTest\unknown.ico")
              ImageList01.ListImages.Add , "Non Toxic", LoadPicture(GetIconsPath & "IconsTest\Non_toxic.ico")
              ImageList01.ListImages.Add , "Toxic", LoadPicture(GetIconsPath & "IconsTest\Toxic.ico")
              End Function
              
              Public Function Load_ImageCombo01()
              With ImageCombo01.ComboItems
                  .Clear
                  .Add Text:="Unknown", Image:=1
                  .Add Text:="Non Toxic", Image:=2
                  .Add Text:="Toxic", Image:=3
              End With
              Call setImageCombo01Selection
              End Function
              
              Public Function setImageCombo01Selection()
                   If ImageCombo01.Tag = Null Then
                       ImageCombo01.Tag = 1
                   ElseIf Len(ImageCombo01.Tag) > 0 Then
                       ' Find the Previously Selected Item
                       For Each oItem In ImageCombo01.ComboItems
                           If oItem = ImageCombo01.Tag Then
                              ImageCombo01.SelectedItem = oItem
                              Exit For
                           End If
                       Next oItem
                   Else
                       ' Select the default item.
                       Set ImageCombo01.SelectedItem = ImageCombo01.ComboItems(3)
                   End If
               End Function
              
              Public Function Load_ImageList02() As String
              ImageList02.ListImages.Clear
              ImageList02.ListImages.Add , "Unknown", LoadPicture(GetIconsPath & "IconsTest\Unknown.ico")
              ImageList02.ListImages.Add , "Light", LoadPicture(GetIconsPath & "IconsTest\ST_Light.ico")
              ImageList02.ListImages.Add , "Normal", LoadPicture(GetIconsPath & "IconsTest\ST_Normal.ico")
              ImageList02.ListImages.Add , "Heavy", LoadPicture(GetIconsPath & "IconsTest\ST_Heavy.ico")
              End Function
              Public Function Load_ImageCombo02()
              With ImageCombo02.ComboItems
                  .Clear
                  .Add Text:="Unknown", Image:=1
                  .Add Text:="Light", Image:=2
                  .Add Text:="Normal", Image:=3
                  .Add Text:="ST_Heavy", Image:=4
              End With
              If ImageCombo02.Tag = Null Then
                  ImageCombo02.Tag = 1
              Else
              ' Select the default item.
                  Set ImageCombo02.SelectedItem = ImageCombo02.ComboItems(1)
              End If
              End Function
              
              
              Public Function GetIconsPath() As String
                  GetIconsPath = GetDBPath
              End Function
              
              Public Function GetDBPath() As String
                  GetDBPath = CurrentProject.Path & "\"
              End Function
              
              Private Sub ImageCombo01_Exit(Cancel As Integer)
                  ImageCombo01.Tag = ImageCombo01.SelectedItem
              End Sub
              
              Private Sub ImageCombo01_Updated(Code As Integer)
                  Debug.Print ImageCombo01.SelImage
              End Sub
              
              Private Sub tabControl01_Change()
                  Select Case Me.tabControl01.Value
                      Case 0
                          Call Load_ImageList01
                          Call Load_ImageCombo01
                      Case 1
                          Call Load_ImageList02
                          Call Load_ImageCombo02
                  End Select
              End Sub

              Comment

              • Breixo
                New Member
                • Dec 2014
                • 11

                #8
                Well, after "throwing in the towel" I've follow "testing" and I've gotten that ImageControls appear correctly when switching pages of the TabControl. To do this I've changed slightly your code:
                First off all, I don't load the second ImageControl (in page02) until I commute the TabControl to the page02:
                Code:
                Private Sub Form_Load()
                    Call load_ImageList00
                    Call Load_ImageList01
                    'Call Load_ImageList02  
                    Call Load_ImageCombo00
                    Call Load_ImageCombo01
                    'Call Load_ImageCombo02
                End Sub
                Here are the variations of your code (This routine gave me many incomprehensibl e errors):
                Code:
                Public Function Load_ImageCombo01()
                With ImageCombo01.ComboItems
                    .Add Text:="Unknown", Image:=1
                    .Add Text:="Non Toxic", Image:=2
                    .Add Text:="Toxic", Image:=3
                End With
                If Len(ImageCombo01.Tag) > 0 Then
                      ' Find the Previously Selected Item
                        For Each oItem In ImageCombo01.ComboItems
                           If oItem = ImageCombo01.Tag Then ImageCombo01.SelectedItem = oItem
                           Exit For
                        Next oItem      
                        Debug.Print "NEW01="; ImageCombo01.SelectedItem
                    Else
                        ' Select the default item.
                        Set ImageCombo01.SelectedItem = ImageCombo01.ComboItems(1)
                        Debug.Print "DEF01="; ImageCombo01.SelectedItem
                    End If
                End Function
                Finally, the code for the TabControl switch:

                Code:
                Private Sub tabControl01_Change()
                    Select Case tabControl01.Value
                        Case 0
                            ImageList01.ListImages.Clear
                            Call Load_ImageList01
                            Call Load_ImageCombo01
                        Case 1
                            ImageList02.ListImages.Clear
                            Call Load_ImageList02
                            Call Load_ImageCombo02
                    End Select
                End Sub
                So far, everything seems fine. The ImageControls are loaded correctly and thus always remain when the TabControl is switched.

                But, whenever you switch to the other page the ImageControls return to the "default".

                I've tried both in the event of "Exit" and "Update" with the following code;
                Code:
                Private Sub ImageCombo01_Updated(Code As Integer)
                   ImageCombo01.Tag = ImageCombo01.SelectedItem
                End Sub
                But it seems useless.

                Please, what am I doing wrong?.

                Comment

                • Breixo
                  New Member
                  • Dec 2014
                  • 11

                  #9
                  Oops!, your message has been crossed with me. Let me try it tonight (here are 22:00).

                  Tomorrow I will tell you if it works !!! Thanks again

                  Comment

                  • Breixo
                    New Member
                    • Dec 2014
                    • 11

                    #10
                    Hi jforbes,

                    Well, a little makeup and everything works perfectly!!!
                    Thank you very much for your time and your attention.
                    Best regards,

                    Comment

                    Working...