Solved

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

Posted on 2000-05-18
6
826 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now