Solved

How can I remove the imagelist binding with the list view at runtime ?

Posted on 2000-05-18
6
839 Views
Last Modified: 2011-09-20
I am getting an error like this
"Image List cannot be modified while other control is bound to it" ,when I
try to delete an image from an imagelist control that I have already used.

How can I remove the imagelist binding with the list view at runtime ?
0
Comment
Question by:amrishsoni
6 Comments
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2820873
You'll need to do a:

Set control.Imagelist = nothing

0
 

Accepted Solution

by:
PatriceF earned 200 total points
ID: 2820886
Here is a sample:

' Remove the imagelist from listview
Set ListView1.Icons = Nothing
Set ListView1.SmallIcons = Nothing
Set ListView1.ColumnHeaderIcons = Nothing

' Empty the image list
ImageList1.ListImages.Clear
' Addd dynamically one image
ImageList1.ListImages.Add "1", , LoadPicture("c:\dts.ico")
' Rebound the picture list
Set ListView1.SmallIcons = ImageList1

0
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2820897
Here's an example I tried:

when the program loads, I bind the toolbar to the imagelist and then set one of the button images. In the double click event, I unbind the control, remove an image from the imagelist, add a new image, rebind the control and then reset the image. This did appear to work fine.

Private Sub Form_DblClick()

  On Error GoTo Form_DblClick_Error
 
'Unbind imagelist
  Set tbrMain.ImageList = Nothing
'Remove image
  ilsTest.ListImages.Remove 1
'Load in a new image
  ilsTest.ListImages.Add , "test", LoadPicture("D:\FABSUITE\test.ico")
'Rebind imagelist control to toolbar
  Set tbrMain.ImageList = ilsTest
'Rebind button to image
  tbrMain.Buttons(1).Image = "test"

Form_DblClick_exit:
  Exit Sub
 
Form_DblClick_Error:
  MsgBox Err.Description, , "Form_DblClick"
  Resume Form_DblClick_exit
 
End Sub

Private Sub Form_Load()

  On Error GoTo Form_Load_Error
 
'Bind imagelist to toolbar
  Set tbrMain.ImageList = ilsTest
'Bind image to button
  tbrMain.Buttons(1).Image = "test"

Form_Load_Exit:
  Exit Sub
 
Form_Load_Error:
  MsgBox Err.Description, , "Form_Load"
  Resume Form_Load_Exit
 
End Sub



0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 1

Expert Comment

by:ofirg
ID: 2820959
You must set all associated control's Property using your imagelist to nothing
and after your changes set them back

Public Sub ChangeImageList(frm As Form, iml As ImageList)
   
    Dim Ctrl As Control
    Dim Col As Collection

    For Each Ctrl In frm.Controls
        If (TypeOf Ctrl Is TreeView) Or (TypeOf Ctrl Is TreeView) Or (TypeOf Ctrl Is TabStrip) Then
            If Ctrl.ImageList = iml Then
                Set Ctrl.ImageList = Nothing
                Col.Add (Ctrl)
            End If
        End If
    Next Ctrl

    ' change your image list

    For Each Ctrl In Col
        Set Ctrl.ImageList = iml
    Next Ctrl

End Sub



Joy And Happiness
0
 
LVL 15

Expert Comment

by:StingRaY
ID: 2821380
You just unbind all involved controls.
By setting .ImageList = nothing
Now you can remove them.
0
 

Author Comment

by:amrishsoni
ID: 2836157
Hi PatriceF,

Thanks for the answer.. It was really
helpful..

Only thing that needs to be added is
You have to again add the List items
into your listview from the binded imagelist..

thanks,

Amrish
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question