Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DatagridView Memory Issues when displaying images C#

Status
Not open for further replies.

l.levine

Programmer
Apr 3, 2017
1
0
0
US
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 !

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top