|
-
April 3rd, 2017, 12:19 PM
#1
Out of memory when populating a datagridview with images
I've used a datagridview many times in the past without any issues, but this is the first time I am trying to display an image in one and I'm coming across an issue that I could use some help with.
The datagridview only has 2 columns associated with it. One for the actual image, and one for the path that indicates where the images exists.
Here is the code that I am using to load images into a datagridview:
Code:
// private void ViewImages_Load(object sender, EventArgs e)
{
try
{
// if item id is not empty, add it to the form title
if (string.IsNullOrEmpty(sItemID) == false)
this.Text = this.Text + sItemID;
int iCell = 0;
// get all the files that exist for the item so we can display them on the screen
string[] files = System.IO.Directory.GetFiles(SelectedImagePath, "[Image]." + sItemID + "_*.jpg");
foreach (string s in files)
{
dataGridView1.Rows.Add(Bitmap.FromFile(s), s);
dataGridView1.Rows[iCell++].Height = 500; // make cell height bigger
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
The first time I load this form I don't encounter an error, but the second time I try to load this form , I get an out of memory error.
I am only trying to populate this datagridview with < 10 images.
Can anyone assist me with figuring how what needs to be done to resolve this issue ?
T U !
Last edited by 2kaud; April 3rd, 2017 at 01:02 PM.
Reason: Fixed code tags
Tags for this Thread
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
|