Exactly what Nishantha said - but to pick out the relevant bits :
Add column to grid:
- Code: Select all
grdLines.AddColumn("Image", new FarPoint.Win.Spread.CellType.ImageCellType(), "Image", 20, false, true, true, true);
Handle lookup button to select an image from file system:
- Code: Select all
private void grdLines_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
{
FarPoint.Win.Spread.Column column = grdLines.ActiveSheet.Columns[e.Column];
string RecID = grdLines.get_GridText("RecID", e.Row).ToString();
bool isNew = (RecID == null || RecID.Trim().Length == 0);
if (column.Tag.ToString() == "Bin")
{
if (RecID.Trim().Length > 0)
{
BusinessLogic.Remove(BusinessLogic[RecID]);
}
}
else if (column.Tag.ToString() == "ImageLookup")
{
JiwaFinancials.Jiwa.JiwaApplication.Image.Image image = null;
if (isNew)
{
string[] files = BrowseForImageFiles(true);
if (files != null)
{
foreach (string filename in files)
{
image = Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaApplication.Image.Image>();
image.ImageBinary = System.IO.File.ReadAllBytes(filename);
image.Name = System.IO.Path.GetFileNameWithoutExtension(filename);
BusinessLogic.Add(image);
}
}
}
else
{
image = BusinessLogic[RecID];
string[] files = BrowseForImageFiles(false);
if (files != null)
{
image.ImageBinary = System.IO.File.ReadAllBytes(files[0]); ;
}
}
}
}
public string[] BrowseForImageFiles(bool MultiSelect)
{
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog
{
Title = "Select Image",
Filter = @"All Files (*.*)|*.*|All Pictures (bmp,gif,jpg,png,wmf)|*.bmp;*.gif;*.jpg;*.png;*.wmf|Bitmaps (*.bmp,*.dib)|*.bmp;*.dib|GIF Images (*.gif)|*.gif|JPEG Images (*.jpg)|*.jpg|PNG Images (*.png)|*.png|Metafiles (*.wmf)|*.wmf",
Multiselect = MultiSelect,
InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
};
if (openFileDialog.ShowDialog(this.Form) == System.Windows.Forms.DialogResult.OK)
{
return openFileDialog.FileNames;
}
return null;
}
Display of image in row (typically in the "displayLine" routine):
- Code: Select all
grdLines.set_GridText("Image", Row, item.ImageBinary);
grdLines.ActiveSheet.Rows[Row].Height = grdLines.ActiveSheet.Rows[Row].GetPreferredHeight();
At the business logic side, the ImageBinary referred to in the above UI code is simply a property of type byte array.