[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2000-05-18
6
Medium Priority
?
892 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses

649 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