amrishsoni
asked on
How can I remove the imagelist binding with the list view at runtime ?
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 ?
"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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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\t est.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
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\t
'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
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
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
You just unbind all involved controls.
By setting .ImageList = nothing
Now you can remove them.
By setting .ImageList = nothing
Now you can remove them.
ASKER
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
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
Set control.Imagelist = nothing