Hi all,
I am using a listview and have images being shown in the first column, however these images do not show up every time. Every now and then, there is no set pattern, the images do not show and there is an empty space instead.
If anyone can help me it would be greatly appreciated.
Thanks in advance

Images do not appear in listview
J. Hammer
More relevant perhaps is that your app is behaving as though the garbage collector is disposing your images. That would explain the random behavior. Test that theory first by calling GC.Collect() after you've loaded the images. If that reliably produces blank images, the LoadIcon() function would be the possible cause. GDI+ is funky about loading images, if it loads them from a file, it keeps a lock on the file handle. Something similar may happen when it loads them from a stream. The 'stream' and 'reader' local variables would definitely be garbage collected...
Amde
Thanks for the help so far nobugz, however the GC.Collect() did not change anything. Images are still shown and not shown at random times.
Mohan1
I don't know if this has anything to do with missing images, but i was testing various ideas and noticed that the Handle of
StatusImageList
was changing. I ran 100 tests of the program and recieved the following results:
The results are interesting because it shows that certain handles show the images whilst others do not. Could this be the reason the images do not show
Gianpi
Ed Steele
Dim stream As System.IO.Stream = LoadResource( strIdentifier, bShared )
Dim reader As System.IO.StreamReader = New System.IO.StreamReader( stream )
Return New System.Drawing.Icon( reader.BaseStream ).ToBitmap()
reader.Close() // try this or something that will close the stream
The other thing is that the xml where the icon setting is coming from might not be properly release
coder2k
andyedw
SivaS
Below is the code to view the images.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
When this form loads the images do no always show, trying to post the cResources.Instance.StatusImageList code is going to be harder because i have inherited this code from some one else and trying to break down what is happening to post something here is goign to take some time.
I have found out some more, when the images do not show up the cResources.Instance.StatusImageList does have the images loaded.
I have also been able to find the code for loading the images
Do 'Get the icon from the element representing this status Dim attIcon As System.Xml.XmlAttribute = elmStatus.Attributes( XML_ATTR_ICON )Debug.Assert(
Not attIcon Is Nothing ) 'Load the named icon from resource Dim icon As System.Drawing.Image = Nothing If ( Not attIcon.Value = String.Empty ) Dim strResource As String = attIcon.ValueConsole.WriteLine( strResource )
icon = LoadIcon( strResource,
True ) Else End If 'Add the icon to the statius image listDebug.Assert( Not icon Is Nothing )
m_StatusImageList.Images.Add( icon )
elmStatus = elmStatus.NextSibling
Loop While ( Not ( elmStatus ) Is Nothing )The Load Icon function
Public Function LoadIcon( ByRef strIdentifier As String, Optional ByVal bShared As Boolean = False ) As System.Drawing.Image
End Function
The load resource function
Public Function LoadResource( ByVal strResource As String, Optional ByVal bShared As Boolean = False ) As System.IO.Stream Dim resource As System.IO.Stream = Nothing If ( Not bShared ) 'Prepend the resource name with the application name Dim strAssemblyName() As String = Reflection.Assembly.GetEntryAssembly.FullName.Split( "," )strResource = strAssemblyName( 0 ) & "." & strResource
resource = Reflection.Assembly.GetEntryAssembly.GetManifestResourceStream( strResource )
Else 'Prepend the resource name with the shared module assembly namestrResource = "ClientShared." & strResource
resource = Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream( strResource )
End If 'Load the resourceDebug.Assert(
Not resource Is Nothing ) Return resource End FunctionIt appears that despite the images being loaded into the imagelist, they are not being shown up. I have tracked the flow in visual studios and have checked at every step of the way that the images are present, and i can say that they are. This is why this problem is really bugging me, because there does not seem to be an answer.
Any help would be appreciated.
Thanks
hrubesh
Mr.Yesser
D--
Thanks you the effort, i'll keep trying things and if i get a solution i'll post it here.
Scott_P
A reboot dosen't fix the problem, whether the images show up or not seems completely random. I cannot seem to work out why and have been working on this for quite a while and have got very fustrated.
I have loaded the images into a image list and then when the list view is shown the images should appear in the first column, this does not always happen and i cannot seem to track down why.
dumian
As far as i can tell no, there is always images in the image list and when the images do not show up, there is no images in the program at all. However, the next time the program loads the images appear. There is no constant action that makes the images not appear, which makes it hard to find a solution.
Salvatore Di Fazio
I've come across
ListView_SetImageList
Does anyone know if it could solve the problem and how to use it