picturebox in Listbox is lost

L

Limin

I add some picturebox in the listbox as controls like following.
Dim myPic as PictureBox
'Init myPic from here
'...
'...
for i=0 to 30
'New picturebox
'...
'set mypic property
'....
ListBox.Controls.Add(myPic)
next

When there is more PictureBox than the ListBox can display,
Vertical Scrollbar will appear. The problem is if user moves the
scrollbar up and down too fast, the picturebox in the ListBox will
disappear. Seems the controls in the listbox lost. Does anyone have
the same problem? How to solve it? Thanks!
 
H

Herfried K. Wagner [MVP]

Limin said:
I add some picturebox in the listbox as controls like following.
Dim myPic as PictureBox
'Init myPic from here
'...
'...
for i=0 to 30
'New picturebox
'...
'set mypic property
'....
ListBox.Controls.Add(myPic)
next

When there is more PictureBox than the ListBox can display,
Vertical Scrollbar will appear. The problem is if user moves the
scrollbar up and down too fast, the picturebox in the ListBox will
disappear.

What's the reason for adding pictureboxes to a listbox? If you want to
associate images with the items of a list, use a listview control instead of
the listbox control, or write an ownerdrawn listbox control that paints the
images into the items.
 
L

Limin He

Thanks for your reply, Mr. Wagner.

The reason I want to add picturebox to listbox not listview is I
dynamically create picturebox, but the picturebox does not have image
information, I only use picturbox's backcolor to display different
colors. The listbox contains both text(Department Name) and color(Legend
bar for Department Name), it works fine only except if scrollbar moves
fast it will lose the picturebox.

But with listview, I need to add smallimagelist which created from ICONS
or BMPFILE, but I don't have image info. for that.

Thanks again for you help. Happy New Year!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top