This happens because if you are using the byte[]
type to represent your image data.
The GridControl itself can correctly operate with bytes directly and correctly convert Bitmap into image-bytes and back. That's why there is no problem in Inplace edit mode.
When working in EditForm mode, the standard WinForms binding is used to pass image-data into EditForm's editor and back. And the standard binding can't convert the Bitmap which you're loaded into the PictureEdit back to image-bytes array. That's why you see the validation error.
To overcome this issue you should either avoid types conversion via using the exact Image
type to represent image-data or patch the standard binding as follows:
public class Person {
public byte[] Photo { get; set; }
}
//...
gridView1.OptionsBehavior.EditingMode = DevExpress.XtraGrid.Views.Grid.GridEditingMode.EditForm;
gridView1.EditFormPrepared += gridView1_EditFormPrepared;
gridControl1.DataSource = new List<Person> {
new Person()
};
//...
void gridView1_EditFormPrepared(object sender, DevExpress.XtraGrid.Views.Grid.EditFormPreparedEventArgs e) {
var binding = e.BindableControls["Photo"].DataBindings["EditValue"];
binding.Parse += binding_ParseImageIntoByteArray;
}
void binding_ParseImageIntoByteArray(object sender, ConvertEventArgs e) {
Image img = e.Value as Image;
if(img != null && e.DesiredType == typeof(byte[])) {
using(var ms = new System.IO.MemoryStream()) {
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
// get bytes
e.Value = ms.GetBuffer();
}
}
}