Results 1 to 3 of 3

Thread: [RESOLVED] Looping through files that are in a ListView?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Resolved [RESOLVED] Looping through files that are in a ListView?

    I have a scenario where I have a Listview that contains Image files and their paths. I need to loop through the listview and retrieve each file and it's width and height and I'm not sure how to set this up in C# (I'm just beginning to learn C#).

    Thanks,
    Blake

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Looping through files that are in a ListView?

    Firstly, if you're well-versed in VB and learning C# then it might be beneficial to download and install Instant C# from Tangible Software Solutions. It will generally provide a 100% accurate conversion for even complex code using new features. You can then write code to do what you want in VB and generate an equivalent C# version.

    As for this specific question, it depends exactly what you mean regarding the Images. The Images displayed in a ListView come from an ImageList and it determines the Size of those Images. If you want the Size of the original Image then you would need to retain a reference to the original Image rather than using the one in the ImageList. You could store that Image in the Tag property of the ListViewItem or you could create a new Image from the path as you loop, e.g.
    csharp Code:
    1. foreach (ListViewItem item in listView1.Items)
    2. {
    3.     var filePath = item.Text;
    4.     int imageWidth;
    5.     int imageHeight;
    6.  
    7.     using (var image = Image.FromFile(filePath))
    8.     {
    9.         imageWidth = image.Width;
    10.         imageHeight = image.Height;
    11.     }
    12.  
    13.     // ...
    14. }

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Looping through files that are in a ListView?

    That's exactly what I was looking for. Also, I never knew about that website for Code Converters. That's a great site.

    Thanks jmc
    Blake

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