Solved

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

Posted on 2000-05-18
6
843 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 82
MS Access - Capture pressed key onclick 4 41
VB6 - Convert HH:MM into Decimal 8 62
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 54
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 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