Populating a DataGridViewImageColumn.
Hi, I have a problem with the following code, I need to read three cells and build up an ImagePath and add it to a root Path, with that path I need to populate the ImageColumn. When the code runs all I get are blank Image Boxes.
private DataSet InitializeDataGridViewer(string connectionString)
{
string commandString = "Select * From SMASTER";
OleDbDataAdapter DataAdapter = new OleDbDataAdapter(commandString, ConnectionString);
DataSet DataSet = new DataSet();
DataAdapter.Fill(DataSet, "SMASTER");
dataGridView1.DataSource = DataSet.Tables["SMASTER"].DefaultView;
DataGridViewImageColumn imageColumn;
imageColumn = new DataGridViewImageColumn();
imageColumn.HeaderText = "1st Image";
imageColumn.Name = "1stImage";
dataGridView1.Columns.Add(imageColumn);
foreach (DataGridViewRow row in dataGridView1.Rows)
{
try
{
RawImagePath = row.Cells["PATH"].Value.ToString() +
"\\" +
row.Cells["BATCH_NO"].Value.ToString() +
row.Cells["STARTID"].Value.ToString() +
".tif";
}
catch
{
continue;
}
string fullPath = imagePaths[0] + "\\" + RawImagePath;
string newfullstring = fullPath.Substring(10, fullPath.Length - 10);
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Bitmap myBitmap = new Bitmap(newfullstring);
Image myThumbnail = myBitmap.GetThumbnailImage(40, 60, myCallback, IntPtr.Zero);
row.Cells["1stImage"].Value = myThumbnail;
//row.Cells["1stImage"].Value = imageColumn.Image = myThumbnail;
dataGridView1.Update();
Application.DoEvents();
}
return DataSet;
}
public bool ThumbnailCallback()
{
return false;
}
Now when I run the version with the commented lines swaped, When run, instead of a different image (According to the path), all I get is the same image in each cell.
Any help would be welcome.
Thanks in advance,
Robert Kelly.
|