|
-
Jan 11th, 2005, 10:39 PM
#1
Thread Starter
Frenzied Member
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
-
Jan 12th, 2005, 07:36 AM
#2
Re: Dynamic ListViewItem image at runtime
Whats the problem with populating an imagelist at runtime?
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ImageList1.Images.Add(Image.FromFile("C:\icontest\1.ico"))
ImageList1.Images.Add(Image.FromFile("C:\icontest\2.ico"))
ImageList1.Images.Add(Image.FromFile("C:\icontest\3.ico"))
ListView1.LargeImageList = ImageList1
ListView1.Items.Add(New ListViewItem("One", 0))
ListView1.Items.Add(New ListViewItem("Two", 1))
ListView1.Items.Add(New ListViewItem("Three", 2))
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:
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.
-
Jan 12th, 2005, 09:42 AM
#3
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|