Results 1 to 5 of 5

Thread: imagelist isnt initialized problem...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    81

    imagelist isnt initialized problem...

    I have a toolbar and an imagelist control assigned to it. I load images into the imagelist and create buttons in the toolbar in runtime.

    Dim listimg_temp As ListImage
    Set listimg_temp = ImageList1.ListImages.Add(...)

    Dim btn As Button
    Set btn = Toolbar1.Buttons.Add(...)

    but sometimes I need to clear both of them and recreate them in runtime again.

    Toolbar1.Buttons.Clear
    ImageList1.ListImages.Clear 'ERROR! why? and how to solve this?

    plz help

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: imagelist isnt initialized problem...

    You can't delete or insert images to an imagelist that have been bound to a toolbar (you can add images to the end of the collection but not insert images). So what you have todo is to set the ImageList property of the Toolbar to nothing before you clear the images.
    VB Code:
    1. Toolbar1.Buttons.Clear
    2. Set Toolbar1.ImageList = Nothing
    3. ImageList1.ListImages.Clear
    4. Set Toolbar1.ImageList = ImageList1

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    81

    Re: imagelist isnt initialized problem...

    Quote Originally Posted by Joacim Andersson
    You can't delete or insert images to an imagelist that have been bound to a toolbar (you can add images to the end of the collection but not insert images). So what you have todo is to set the ImageList property of the Toolbar to nothing before you clear the images.
    VB Code:
    1. Toolbar1.Buttons.Clear
    2. Set Toolbar1.ImageList = Nothing
    3. ImageList1.ListImages.Clear
    4. Set Toolbar1.ImageList = ImageList1
    yes. I have tried exactly the same too, but it also doesnt work.

    the line:
    Set Toolbar1.ImageList = ImageList1
    cause error: Imagelist must be initialized before it can be used!

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: imagelist isnt initialized problem...

    Oh yeah sorry. You must add at least one image to the ImageList before you can set it back to the Toolbar.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    81

    Re: imagelist isnt initialized problem...

    thanx, it works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width