-
May 5th, 2018, 11:53 PM
#1
Thread Starter
PowerPoster
[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,
-
May 6th, 2018, 12:09 AM
#2
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:
foreach (ListViewItem item in listView1.Items) { var filePath = item.Text; int imageWidth; int imageHeight; using (var image = Image.FromFile(filePath)) { imageWidth = image.Width; imageHeight = image.Height; } // ... }
-
May 6th, 2018, 12:23 AM
#3
Thread Starter
PowerPoster
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
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
|