INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

DatagridView Memory Issues when displaying images C#

DatagridView Memory Issues when displaying images C#

(OP)
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:
private void ViewImages_Load(object sender, EventArgs e)
{
// 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
}

}

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 !

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close