Results 1 to 3 of 3

Thread: Dynamic ListViewItem image at runtime

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Dynamic ListViewItem image at runtime

    It's easy enough to set the ListViewItem's icon when you already have an ImageList defined. What should you do when you need to read the icon file name from a DB at runtime?

    DB stuff is no problem. But it seems I would have to populate an ImageList at runtime to load up the icon from disk. The app needs to refresh often, and also notice new entries. My problem is that there seems to be no way to refer to an entry in the ImageList besides it's index. How can I tell if I should load up an image, or just re-use one that's already there?

    Thanks,
    Mike

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Dynamic ListViewItem image at runtime

    Whats the problem with populating an imagelist at runtime?

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         ImageList1.Images.Add(Image.FromFile("C:\icontest\1.ico"))
    4.         ImageList1.Images.Add(Image.FromFile("C:\icontest\2.ico"))
    5.         ImageList1.Images.Add(Image.FromFile("C:\icontest\3.ico"))
    6.  
    7.         ListView1.LargeImageList = ImageList1
    8.  
    9.         ListView1.Items.Add(New ListViewItem("One", 0))
    10.         ListView1.Items.Add(New ListViewItem("Two", 1))
    11.         ListView1.Items.Add(New ListViewItem("Three", 2))
    12.  
    13.     End Sub

    You could keep a string array that holds all the icon filenames currently loaded, when checking for updates, do a binary search for the path in the array...

    VB Code:
    1. Array.BinarySearch(MyArray, "c:\...\MyIcon.ico")

    If the path is found just use the one in the imagelist. Otherwise load it into the imagelist before using it.

    Or is that not the problem?
    I don't live here any more.

  3. #3

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: Dynamic ListViewItem image at runtime

    No, that's exactly what I was wondering, that is, the best way to go about it. Guess I was looking for a .Tag property for each image, but I guess a string array would serve the same purpose.

    Thanks for the input.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width