[Closed] ImageList.ListImages.Clear() –error with ActiveX
I am trying to use a ListView with the icons set to an imageList for asset browsing and placement in a scene, but I am having trouble dynamicly loading and creating the imageList due to an error that won’t let me clear the list. I have tried
<myImageList>.ListImages.Clear()
and
<myImageList>.ListImages.Remove <index>
to no avail. I am always getting an error with these calls. My question is, how can I dynamicly change the image array to new values, in order to display a different list of icons in the ListView activex control? The Max help is pretty limited in this area.
Thanks.
–Ben
I don’t think this is a max limitation. If I remember correctly, older versions of the imageList control do not allow changes to the list when the control is bound to another activexcontrol (like listview). IF I’m right about this, you probably need to unlink the other control first, then make the changes, and link it back again.
Cheers,
Martijn
That seems to make sense. I am initializing the ImageList, and passing it into the ListView control like this:
allAssetImages = #() -- initialized to contain all bmp files in a directory
-- structure defining the asset data
struct myAsset
{
icn, --"<drive>:/projectFolder/Skyscrapers/Skyscraper_001/Skyscraper_001_icn.bmp"
name, -- "Skyscraper_001"
filename, --"<drive>:/projectFolder/Skyscrapers/Skyscraper_001/Skyscraper_001.FLT"
category, --"Skyscrapers"
icnIndex -- some int for the index that this assets icn is in the imgList
}
-- this array of myAssets is created and filled with the list of available assets
aArray = #(asset1,asset2..., assetN)
fn initImgList imgList lv =
(
print "Initializing the image library..."
local start = timestamp()
-- this is where I get a system error, thus the try-catch statement. It has never
-- cleared the array, possibly because the ListView has it's icons set to this
-- imageList?
try(imgList.listImages.Clear())catch()
imgList.imageWidth = iWidth
imgList.imageHeight = iHeight
-- right now I am filling another array of just the bmp files found on disk of all the
-- assets. this is verry slow, and loadPicture sometimes fails. I want to just load the
-- bmp's of a specific asset category, so I am loading only 15-20 images, as
-- opposed to 150 or so.
for i=1 to allAssetImages.count do
(
local icn = ( loadPicture ( allAssetImages[i] as string ))
try ( imgList.listImages.add i #nullName ( icn ) )
catch ( )
)
local end = timestamp()
print ((end-start) as string + " ms to complete.")
)
-- function to fill the list with the images and labels
-- aArray must be defined prior to this function call
fn fillList lv =
(
lv.ListItems.Clear()
for i=1 to aArray.count do
(
li = lv.ListItems.add()
li.icon = aArray[i].icnIndex
li.text = (aArray[i].name )--+ " " + aArray[i].icnIndex as string)
)
)
fn initList listView imgList =
(
listView.gridLines = false
listView.view = #lvwIcon
listView.fullRowSelect = true
initImgList imgList listView
-- when I change categories, and clear the ListView, do I also have to set this to
-- undefined? 0? How do I detatch the Icons from the ImageList, so I can clear the
-- imageList and fill it with a new array of images?
listView.Icons = imgList
fillList listView
)
Hope this clarifies how I am trying to do this. Thanks for the help.
I am initializing the Image List like this.
activeXControl myAssetImages “MSComctlLib.ImageListCtrl.2” height:0 width:0
and assigning it to the ListView.Icons after it is initialized.
myListView.Icons = myAssetImages
How do I disconnect the imagelist from the list-view icons in order to make changes to the list view?
Haven’t tried this but you might be able to just say:
myListView.Icons = undefined
Another method might be to create a second imagelist and temporarily assign that one to the listview icons property.
- Martijn