HOW TO: ListView & TreeView Bitmaps WITHOUT ImageList

HOW TO: ListView & TreeView Bitmaps WITHOUT ImageList

Post by Enzo Trapan » Sun, 26 Aug 2001 18:02:24

Hi to all,
I'm stuck with a code problem: I need to implement graphics in controls like
ListView and TreeView, but I absolutely don't want to use the associated
ImageList control, because of its memory problems and instability. I
packaged a DLL containing all the bitmaps I need for my apps and I would
like to use them on demand (a huge load when the app starts fills up the
entire capacity of the ImageList).

The matter is as follows:
Original project includes one form with one EMPTY ImageList control in it;
run-time procedure fills up the ImageList with bitmaps coming from a huge
DLL, via For Next cycle;

For i = 3 To cResource.LoadString(9000)
        Set img = imlBitmap16.ListImages.Add(i, , cResource.LoadBitmap(i))

after that I have more than 500 images loaded and my EXE is OK in size,
which wouldn't occurr if I decided to store all the bitmaps design-time.
With this I can bind the ImageList to any ListView
cListView.SetHeaderColour ctl, True
ctl.ColumnHeaderIcons = frmBitmapForm.imlBitmap16

or TreeView,
ctl.ImageList = frmBitmapForm.imlBitmap16

or TabStrip in my project
ctl.ImageList = frmBitmapForm.imlBitmap16

But after this procedure I notice a VB memory overload message, when I try
to open a second copy of VB, or when I run another app, like Access.
So I thought about getting rid of the intrinsic ImageList to be bound to
useful controls like ListView and TreeView.
Wouldn't it be nice to use just one bitmap at a time (right the one you
need) and bind it to the control you need telling the Nodes.Add or
ListItems.Add procedures to use ID numbers from a DLL, instead of loading
all the bitmaps a project may require in an associated ImageList control?

Can anyone send me example code of how this could be achieved?
Any help is really appreciated.