Image List

  • Thread starter Thread starter grzegorz.gazda
  • Start date Start date
G

grzegorz.gazda

Hi all
Is there any limit of images which can be added to a image list. I
have a problem with this control. I added an image list in design mode
and I am adding images using code. Then I want to use images in a
listview, and each time I am trying to call an image at index 15 or
above I have an error stating that there isn't any object at that
index. I was debbuging it and there was more there was 22 images, but
only 15 I can load.

Is there any way I can add and display more than 15 images. What is
causing that problem?

Thanks
 
I doubt there is a limit, but it would probably help us if you posted your
code
 
You can have more than 15 images in an imagelist control.

Not sure of the limitations but way more than 15 I think I had 200 or so
(they were only littel 32x32 icons though)

Mike.
 
I doubt there is a limit, but it would probably help us if you posted your
code

Ok I am posting some code

Dim imgFlag As Image

sCountry = LookUpDetails(row("ip").ToString)
newRow = dsReport.Tables("Countries").Rows.Find(sCountry)
If newRow Is Nothing Then
newRow = dsReport.Tables("Countries").NewRow
newRow("CountryName") = sCountry
newRow("CountryHits") = CInt(row("hits").ToString)
newRow("CountryVisitors") = 1
newRow("CountryCode") =
LookUpCountryCode(row("ip").ToString)
Try
'Adding image to ImageList
imgFlag = Image.FromFile(sImagePath &
newRow("CountryCode").ToString.ToLower & ".gif")

ilCountries.Images.Add(newRow("CountryCode").ToString, imgFlag)

Catch ex As IO.FileNotFoundException
EventLog.WriteEntry("LogAnalyst", "Image file was
not found. Path for desired image: " & sImagePath &
newRow("CountryCode").ToString.ToLower & ".gif",
EventLogEntryType.Error, 100)
End Try

dsReport.Tables("Countries").Rows.Add(newRow)
Else
newRow("CountryHits") += CInt(row("hits").ToString)
newRow("CountryVisitors") += 1
End If

And another bit where error appears

Dim item As ListViewItem

If rows.Length > 0 Then
StatAnalyst.ListView2.StateImageList =
StatAnalyst.ilCountries
For Each row In rows
item = New
ListViewItem(row("CountryName").ToString)
Try
item.StateImageIndex =
StatAnalyst.ilCountries.Images.IndexOfKey(row("CountryCode").ToString)
Catch
End Try
item.SubItems.Add(row("CountryHits").ToString)
item.SubItems.Add(row("CountryVisitors").ToString)
StatAnalyst.ListView2.Items.Add(item)
Next
End If

Error message from exception:
System.ArgumentOutOfRangeException: InvalidArgument=Value of '21' is
not valid for 'StateImageIndex'.
Parameter name: StateImageIndex
at System.Windows.Forms.ListViewItem.set_StateImageIndex(Int32
value)
at Stat_Analyzer.Reports.CreateCountries() in Path\Stat Analyzer
\Stat Analyzer\Reports.vb:line 112

At the moment when error appears there are 22 images in ListView. On
ListView only 15 are displayed properly, only 15 appeared.

I have the same problem with another ListView in which I have 16
items. That list was created using design mode, but when I was trying
to add image from index 15 I got the same error as above.
 
Back
Top