PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[2005] Getting the images in a imagelist-VBForums
Results 1 to 6 of 6

Thread: [2005] Getting the images in a imagelist

  1. #1

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    [2005] Getting the images in a imagelist

    Is there anyway to get the image names that are currently in a listview?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,743

    Re: [2005] Getting the images in a imagelist

    What do you mean by "image names"? The Image class doesn't have a Name property so Image objects don't have names.

    If you mean the name of the files the images were created from then you're out of luck because there's no accessible connection between an Image object and the original file. Of course there's not, because Image objects don't have to come from a file at all.

    If you actually mean the key it was added to the imageList with, then that would be the ImageList.Images.Keys property, which the MSDN documentation would have told you.

  3. #3

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Re: [2005] Getting the images in a imagelist

    Hm well maybe you can help me out with my problem. Im making a slideshow where the user can add, delete and view pictures. The pictures are contained in a string, for example C:\Pic1|C:\Pic2|C:\stuff\Pic3 ect. My question is how could i use the code below but replace the s with the picture name and then remove the picture from the string?

    vb Code:
    1. dim pic as string = "C:\Pic1|C:\Pic2|C:\stuff\Pic3"
    2. split1 = pic.Split("|")
    3.         For Each str As String In split1
    4.             If str.Trim() <> "" Then
    5.                 ImageList1.Images.Add(Image.FromFile(str))
    6.             End If
    7.         Next str
    8.         For i As Integer = 0 To ImageList1.Images.Count - 1
    9.             ListView1.Items.Add("s", i)
    10.         Next

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,743

    Re: [2005] Getting the images in a imagelist

    You should only have one loop for a start. There's nothing to stop you adding the Image to the ImageList and the item to the ListView at the same time. You should:

    1. Get the file path.
    2. Create the Image.
    3. Add the Image to the ImageList WITH a key.
    4. Create ListViewItem.
    5. Set its ImageKey.
    6. Add the item to the ListView.

    All that should be inside one loop.

  5. #5

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Re: [2005] Getting the images in a imagelist

    Ive been playing around with it and this is what ive come up with so far
    vb Code:
    1. dim pic as string = "C:\Pic1|C:\Pic2|C:\stuff\Pic3"
    2.         split1 = pic.Split("|")
    3.         For Each str As String In split1
    4.             If str.Trim() <> "" Then
    5.                 ImageList1.Images.Add(id, Image.FromFile(str))
    6.                 split1(id) = split1(id).Substring(InStrRev(split1(id), "\"))
    7.                 ListView1.Items.Add(split1(id), id)
    8.             End If
    9.             If id < split1.Length Then
    10.                 id += 1
    11.             End If
    12.         Next str
    13.         Next str
    Last edited by Motoxpro; Nov 13th, 2007 at 04:41 AM.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,743

    Re: [2005] Getting the images in a imagelist

    Wouldn't you just use the file paths as the keys? If you're just going to use numbers then the keys are pointless and you may as well just use indexes.

    Also, I have big issue with variable names like "split1" when something like "fileNames" is obviously far more descriptive of the variable's purpose.
    vb.net Code:
    1. Dim fileNames As String() = pathString.Spit("|"c)
    2. Dim fileName As String
    3. Dim img As Image
    4.  
    5. For index As Integer = 0 To fileNames.GetUpperBound(0)
    6.     fileName = fileNames(index)
    7.     img = Image.FromFile(fileName)
    8.     ImageList1.Images.Add(fileName, img)
    9.     ListView1.Items.Add(IO.Path.GetFileName(fileName), fileName)
    10. Next index

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width