473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ImageList, ImageCombo and TabControl problems

11
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 "ImageCombos" 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?
Feb 14 '15 #1

✓ answered by jforbes

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:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Form_Load()
  4.     Call load_ImageList00
  5.     Call Load_ImageList01
  6.     Call Load_ImageList02
  7.  
  8.     Call Load_ImageCombo00
  9.     Call Load_ImageCombo01
  10.     Call Load_ImageCombo02
  11.  
  12. End Sub
  13. ' LOCATED ON FORM HEADER
  14. Public Function load_ImageList00()
  15. ImageList00.ListImages.Add , "Zone 6 (-23 to -18ºC", LoadPicture(GetIconsPath & "IconsTest\zone06.ico")
  16. ImageList00.ListImages.Add , "Zone 7 (-18 to -12ºC)", LoadPicture(GetIconsPath & "IconsTest\zone07.ico")
  17. ImageList00.ListImages.Add , "Zone 8 (-12 to -7ºC)", LoadPicture(GetIconsPath & "IconsTest\zone08.ico")
  18. ImageList00.ListImages.Add , "Zone 9 (-7 to -1ºC)", LoadPicture(GetIconsPath & "IconsTest\zone09.ico")
  19. End Function
  20.  
  21. Public Function Load_ImageCombo00()
  22. With ImageCombo00.ComboItems
  23.     .Add Text:="Zone 6 (-23 to -18ºC)", Image:=1
  24.     .Add Text:="Zone 7 (-18 to -12ºC)", Image:=2
  25.     .Add Text:="Zone 8 (-12 to -7ºC)", Image:=3
  26.     .Add Text:="Zone 9 (-7 to -1ºC)", Image:=4
  27. End With
  28. If ImageCombo00.Tag = Null Then
  29.     icbZones.Tag = 1
  30. Else
  31.    ' Select the default item. Zone 8
  32.     Set ImageCombo00.SelectedItem = ImageCombo00.ComboItems(3)
  33. End If
  34. End Function
  35.  
  36. ' LOCATED ON FORM DETAIL, tabControl01, Page01
  37. Public Function Load_ImageList01()
  38. ImageList01.ListImages.Clear
  39. ImageList01.ListImages.Add , "Unknown", LoadPicture(GetIconsPath & "IconsTest\unknown.ico")
  40. ImageList01.ListImages.Add , "Non Toxic", LoadPicture(GetIconsPath & "IconsTest\Non_toxic.ico")
  41. ImageList01.ListImages.Add , "Toxic", LoadPicture(GetIconsPath & "IconsTest\Toxic.ico")
  42. End Function
  43.  
  44. Public Function Load_ImageCombo01()
  45. With ImageCombo01.ComboItems
  46.     .Clear
  47.     .Add Text:="Unknown", Image:=1
  48.     .Add Text:="Non Toxic", Image:=2
  49.     .Add Text:="Toxic", Image:=3
  50. End With
  51. Call setImageCombo01Selection
  52. End Function
  53.  
  54. Public Function setImageCombo01Selection()
  55.      If ImageCombo01.Tag = Null Then
  56.          ImageCombo01.Tag = 1
  57.      ElseIf Len(ImageCombo01.Tag) > 0 Then
  58.          ' Find the Previously Selected Item
  59.          For Each oItem In ImageCombo01.ComboItems
  60.              If oItem = ImageCombo01.Tag Then
  61.                 ImageCombo01.SelectedItem = oItem
  62.                 Exit For
  63.              End If
  64.          Next oItem
  65.      Else
  66.          ' Select the default item.
  67.          Set ImageCombo01.SelectedItem = ImageCombo01.ComboItems(3)
  68.      End If
  69.  End Function
  70.  
  71. Public Function Load_ImageList02() As String
  72. ImageList02.ListImages.Clear
  73. ImageList02.ListImages.Add , "Unknown", LoadPicture(GetIconsPath & "IconsTest\Unknown.ico")
  74. ImageList02.ListImages.Add , "Light", LoadPicture(GetIconsPath & "IconsTest\ST_Light.ico")
  75. ImageList02.ListImages.Add , "Normal", LoadPicture(GetIconsPath & "IconsTest\ST_Normal.ico")
  76. ImageList02.ListImages.Add , "Heavy", LoadPicture(GetIconsPath & "IconsTest\ST_Heavy.ico")
  77. End Function
  78. Public Function Load_ImageCombo02()
  79. With ImageCombo02.ComboItems
  80.     .Clear
  81.     .Add Text:="Unknown", Image:=1
  82.     .Add Text:="Light", Image:=2
  83.     .Add Text:="Normal", Image:=3
  84.     .Add Text:="ST_Heavy", Image:=4
  85. End With
  86. If ImageCombo02.Tag = Null Then
  87.     ImageCombo02.Tag = 1
  88. Else
  89. ' Select the default item.
  90.     Set ImageCombo02.SelectedItem = ImageCombo02.ComboItems(1)
  91. End If
  92. End Function
  93.  
  94.  
  95. Public Function GetIconsPath() As String
  96.     GetIconsPath = GetDBPath
  97. End Function
  98.  
  99. Public Function GetDBPath() As String
  100.     GetDBPath = CurrentProject.Path & "\"
  101. End Function
  102.  
  103. Private Sub ImageCombo01_Exit(Cancel As Integer)
  104.     ImageCombo01.Tag = ImageCombo01.SelectedItem
  105. End Sub
  106.  
  107. Private Sub ImageCombo01_Updated(Code As Integer)
  108.     Debug.Print ImageCombo01.SelImage
  109. End Sub
  110.  
  111. Private Sub tabControl01_Change()
  112.     Select Case Me.tabControl01.Value
  113.         Case 0
  114.             Call Load_ImageList01
  115.             Call Load_ImageCombo01
  116.         Case 1
  117.             Call Load_ImageList02
  118.             Call Load_ImageCombo02
  119.     End Select
  120. End Sub
  121.  
  122.  

9 2810
jimatqsi
1,271 Expert 1GB
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
Feb 15 '15 #2
Breixo
11
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 Images
File Type: jpg design_view.jpg (98.8 KB, 395 views)
File Type: jpg behaviour.jpg (141.9 KB, 387 views)
Attached Files
File Type: zip IML_IMC_TAB_TEST.zip (939.5 KB, 114 views)
Feb 15 '15 #3
Breixo
11
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,
Feb 19 '15 #4
jforbes
1,107 Expert 1GB
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.:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ImageCombo01_Exit(Cancel As Integer)
  2.     ImageCombo01.Tag = ImageCombo01.SelectedItem
  3. 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:
Expand|Select|Wrap|Line Numbers
  1. Public Function setImageCombo01Selection()
  2.     If ImageCombo01.Tag = Null Then
  3.         ImageCombo01.Tag = 1
  4.     ElseIf Len(ImageCombo01.Tag) > 0 Then
  5.         ' Find the Previously Selected Item
  6.         For Each oItem In ImageCombo01.ComboItems
  7.             If oItem = ImageCombo01.Tag Then ImageCombo01.SelectedItem = oItem
  8.             Exit For
  9.         Next oItem
  10.     Else
  11.         ' Select the default item.
  12.         Set ImageCombo01.SelectedItem = ImageCombo01.ComboItems(3)
  13.     End If
  14. End Function
Lastly, reinitialize the ImageList and ImageCombo when the Tab is changed:
Expand|Select|Wrap|Line Numbers
  1. Private Sub tabControl01_Change()
  2.     Select Case Me.tabControl01.Value
  3.         Case 0
  4.             Call Load_ImageList01
  5.             Call Load_ImageCombo01
  6.         Case 1
  7.             Call Load_ImageList02
  8.             Call Load_ImageCombo02
  9.     End Select
  10. End Sub
This could be much prettier, but I'll leave that up to you.

Good luck.
Feb 19 '15 #5
Breixo
11
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,
Feb 23 '15 #6
jforbes
1,107 Expert 1GB
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:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Form_Load()
  4.     Call load_ImageList00
  5.     Call Load_ImageList01
  6.     Call Load_ImageList02
  7.  
  8.     Call Load_ImageCombo00
  9.     Call Load_ImageCombo01
  10.     Call Load_ImageCombo02
  11.  
  12. End Sub
  13. ' LOCATED ON FORM HEADER
  14. Public Function load_ImageList00()
  15. ImageList00.ListImages.Add , "Zone 6 (-23 to -18ºC", LoadPicture(GetIconsPath & "IconsTest\zone06.ico")
  16. ImageList00.ListImages.Add , "Zone 7 (-18 to -12ºC)", LoadPicture(GetIconsPath & "IconsTest\zone07.ico")
  17. ImageList00.ListImages.Add , "Zone 8 (-12 to -7ºC)", LoadPicture(GetIconsPath & "IconsTest\zone08.ico")
  18. ImageList00.ListImages.Add , "Zone 9 (-7 to -1ºC)", LoadPicture(GetIconsPath & "IconsTest\zone09.ico")
  19. End Function
  20.  
  21. Public Function Load_ImageCombo00()
  22. With ImageCombo00.ComboItems
  23.     .Add Text:="Zone 6 (-23 to -18ºC)", Image:=1
  24.     .Add Text:="Zone 7 (-18 to -12ºC)", Image:=2
  25.     .Add Text:="Zone 8 (-12 to -7ºC)", Image:=3
  26.     .Add Text:="Zone 9 (-7 to -1ºC)", Image:=4
  27. End With
  28. If ImageCombo00.Tag = Null Then
  29.     icbZones.Tag = 1
  30. Else
  31.    ' Select the default item. Zone 8
  32.     Set ImageCombo00.SelectedItem = ImageCombo00.ComboItems(3)
  33. End If
  34. End Function
  35.  
  36. ' LOCATED ON FORM DETAIL, tabControl01, Page01
  37. Public Function Load_ImageList01()
  38. ImageList01.ListImages.Clear
  39. ImageList01.ListImages.Add , "Unknown", LoadPicture(GetIconsPath & "IconsTest\unknown.ico")
  40. ImageList01.ListImages.Add , "Non Toxic", LoadPicture(GetIconsPath & "IconsTest\Non_toxic.ico")
  41. ImageList01.ListImages.Add , "Toxic", LoadPicture(GetIconsPath & "IconsTest\Toxic.ico")
  42. End Function
  43.  
  44. Public Function Load_ImageCombo01()
  45. With ImageCombo01.ComboItems
  46.     .Clear
  47.     .Add Text:="Unknown", Image:=1
  48.     .Add Text:="Non Toxic", Image:=2
  49.     .Add Text:="Toxic", Image:=3
  50. End With
  51. Call setImageCombo01Selection
  52. End Function
  53.  
  54. Public Function setImageCombo01Selection()
  55.      If ImageCombo01.Tag = Null Then
  56.          ImageCombo01.Tag = 1
  57.      ElseIf Len(ImageCombo01.Tag) > 0 Then
  58.          ' Find the Previously Selected Item
  59.          For Each oItem In ImageCombo01.ComboItems
  60.              If oItem = ImageCombo01.Tag Then
  61.                 ImageCombo01.SelectedItem = oItem
  62.                 Exit For
  63.              End If
  64.          Next oItem
  65.      Else
  66.          ' Select the default item.
  67.          Set ImageCombo01.SelectedItem = ImageCombo01.ComboItems(3)
  68.      End If
  69.  End Function
  70.  
  71. Public Function Load_ImageList02() As String
  72. ImageList02.ListImages.Clear
  73. ImageList02.ListImages.Add , "Unknown", LoadPicture(GetIconsPath & "IconsTest\Unknown.ico")
  74. ImageList02.ListImages.Add , "Light", LoadPicture(GetIconsPath & "IconsTest\ST_Light.ico")
  75. ImageList02.ListImages.Add , "Normal", LoadPicture(GetIconsPath & "IconsTest\ST_Normal.ico")
  76. ImageList02.ListImages.Add , "Heavy", LoadPicture(GetIconsPath & "IconsTest\ST_Heavy.ico")
  77. End Function
  78. Public Function Load_ImageCombo02()
  79. With ImageCombo02.ComboItems
  80.     .Clear
  81.     .Add Text:="Unknown", Image:=1
  82.     .Add Text:="Light", Image:=2
  83.     .Add Text:="Normal", Image:=3
  84.     .Add Text:="ST_Heavy", Image:=4
  85. End With
  86. If ImageCombo02.Tag = Null Then
  87.     ImageCombo02.Tag = 1
  88. Else
  89. ' Select the default item.
  90.     Set ImageCombo02.SelectedItem = ImageCombo02.ComboItems(1)
  91. End If
  92. End Function
  93.  
  94.  
  95. Public Function GetIconsPath() As String
  96.     GetIconsPath = GetDBPath
  97. End Function
  98.  
  99. Public Function GetDBPath() As String
  100.     GetDBPath = CurrentProject.Path & "\"
  101. End Function
  102.  
  103. Private Sub ImageCombo01_Exit(Cancel As Integer)
  104.     ImageCombo01.Tag = ImageCombo01.SelectedItem
  105. End Sub
  106.  
  107. Private Sub ImageCombo01_Updated(Code As Integer)
  108.     Debug.Print ImageCombo01.SelImage
  109. End Sub
  110.  
  111. Private Sub tabControl01_Change()
  112.     Select Case Me.tabControl01.Value
  113.         Case 0
  114.             Call Load_ImageList01
  115.             Call Load_ImageCombo01
  116.         Case 1
  117.             Call Load_ImageList02
  118.             Call Load_ImageCombo02
  119.     End Select
  120. End Sub
  121.  
  122.  
Feb 23 '15 #7
Breixo
11
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Call load_ImageList00
  3.     Call Load_ImageList01
  4.     'Call Load_ImageList02  
  5.     Call Load_ImageCombo00
  6.     Call Load_ImageCombo01
  7.     'Call Load_ImageCombo02
  8. End Sub
Here are the variations of your code (This routine gave me many incomprehensible errors):
Expand|Select|Wrap|Line Numbers
  1. Public Function Load_ImageCombo01()
  2. With ImageCombo01.ComboItems
  3.     .Add Text:="Unknown", Image:=1
  4.     .Add Text:="Non Toxic", Image:=2
  5.     .Add Text:="Toxic", Image:=3
  6. End With
  7. If Len(ImageCombo01.Tag) > 0 Then
  8.       ' Find the Previously Selected Item
  9.         For Each oItem In ImageCombo01.ComboItems
  10.            If oItem = ImageCombo01.Tag Then ImageCombo01.SelectedItem = oItem
  11.            Exit For
  12.         Next oItem      
  13.         Debug.Print "NEW01="; ImageCombo01.SelectedItem
  14.     Else
  15.         ' Select the default item.
  16.         Set ImageCombo01.SelectedItem = ImageCombo01.ComboItems(1)
  17.         Debug.Print "DEF01="; ImageCombo01.SelectedItem
  18.     End If
  19. End Function
Finally, the code for the TabControl switch:

Expand|Select|Wrap|Line Numbers
  1. Private Sub tabControl01_Change()
  2.     Select Case tabControl01.Value
  3.         Case 0
  4.             ImageList01.ListImages.Clear
  5.             Call Load_ImageList01
  6.             Call Load_ImageCombo01
  7.         Case 1
  8.             ImageList02.ListImages.Clear
  9.             Call Load_ImageList02
  10.             Call Load_ImageCombo02
  11.     End Select
  12. 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;
Expand|Select|Wrap|Line Numbers
  1. Private Sub ImageCombo01_Updated(Code As Integer)
  2.    ImageCombo01.Tag = ImageCombo01.SelectedItem
  3. End Sub
But it seems useless.

Please, what am I doing wrong?.
Feb 23 '15 #8
Breixo
11
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
Feb 23 '15 #9
Breixo
11
Hi jforbes,

Well, a little makeup and everything works perfectly!!!
Thank you very much for your time and your attention.
Best regards,
Feb 24 '15 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Allcomp | last post by:
Hello, I would like to change the Forecolor of a comboItem (of a ImageCombo), but I can't make it. I can't see any forecolor in the method or properties. If I change the forecolor of the...
1
by: Keith Smith | last post by:
Is there a way for me to use an image file (JPG, GIF, BMP etc) on my tabs instead of text? I see that if you go to the "Icon" property (of a tabPage) then you can add a ICO file, but because an...
4
by: David | last post by:
I have a problem that just cropped up with using an ImageList in my project I am using VB .NET 200 Problem: I have existing Form with 2 Image List controls. ImageList16 (for 16x16 Images) and...
4
by: Andre Nogueira | last post by:
hi there. I am creating a tabcontrol where the drawing of the tabs is controlled by me. However, i cannot find a way to change the lenght of the tab. For instance, "String" needs a smaller tab...
2
by: marfi95 | last post by:
Is there a way to put an icon in the tabpages of a tabcontrol ? I haven't seen any properties to do this.
0
by: matt | last post by:
I currently have a tabcontrol with 5 tabs. instead of putting text in the tabs i am using images. i created an image list and inserted the 5 images and used them to display instead of text. ...
6
by: henrycortezwu | last post by:
Hi, I have a WinXPSP2, P4 3.2GHZ, 1GIG RAM on my dev machine using VS2005 VB.NET. I did the following procedure: 1. Added 82 icons (128x128 in size & 32bit Depth) in an imagelist control 2....
4
TheSmileyCoder
by: TheSmileyCoder | last post by:
Im trying to have some fun with the imagecombo control, but so far its alot more frustration then it is fun. From what I have understood I can't tie the imagecombobox directly to a field in a...
3
TheSmileyCoder
by: TheSmileyCoder | last post by:
Im using an imagecombo in my form, and I have its Text property set to "Please Select". The text property of the imagecombo is what is displayed when you have not yet made a selection, kinda like...
3
by: Breixo | last post by:
Hi to all, I'm about to go crazy. Attached is a simple form with an ImageList control and an ImageCombo control. The problem is that when I try to associate the ImageCombo with the ImageList, in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.