[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2000-05-18
6
Medium Priority
?
905 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 800 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses
Course of the Month18 days, 13 hours left to enroll

834 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