Set image to RepositoryItemPictureEdit in XtraGrid

Rami Alshareef picture Rami Alshareef · Jan 29, 2013 · Viewed 12.5k times · Source

I have XtraGrid, I've added a new column and set its ColumnEdit property to RepositoryItemPictureEdit. I have tried to set an image to it using RepositoryItemPictureEdit1.Appearance.Image but it does not populate after the form's load, any thoughts why?

I have 2011 version

Answer

Niranjan Singh picture Niranjan Singh · Jan 30, 2013

As i guess you are not assigning image to control in correct way. You can go through this DevExpress KB thread - Why do I get the "No image data" text in the GridColumn with the PictureEdit in-place editor?

Source : Assigning an image to a RepositoryItemPictureEdit
you can use this approach also:
1) Set the column's FieldName property to the "Image" ,as your DataTable contains this Field
2) Set the Image DataColumn type to the Image value
3) Change the code and do not convert an image to a byte array.

Just set it as below:

RepositoryItemPictureEdit pictureEdit = gridControl1.RepositoryItems.Add("PictureEdit") as RepositoryItemPictureEdit;

pictureEdit.SizeMode = PictureSizeMode.Zoom;

pictureEdit.NullText = " ";

gridView1.Columns["Picture"].ColumnEdit = pictureEdit;

To make the editor load images, the underlying data type should correspond to the RepositoryItemPictureEdit.PictureStoreMode property value

If you want to display image in cell then you can use CustomDrawCell Event

Here ImageStream is a property that store image.

 public Stream ImageStream { get; set; }

you can use it as below:

    if (profile != null)
    {
          imageStream = MyObj.ImageStream; // this image saved as stream
    }

}

if (imageStream != null)
{
    e.Graphics.DrawImage(System.Drawing.Image.FromStream(imageStream), e.Bounds);
    if (cellValue.Condition== "XXXX")
    {
        e.Graphics.DrawRectangle(e.Cache.GetPen(Color.Red), e.Bounds);
    }

    e.DisplayText = text;
    Rectangle r = e.Bounds;
    Rectangle w = new Rectangle(r.X, r.Y - 5, r.Width, r.Height);
    //Draw the cell value
    e.Appearance.DrawString(e.Cache, e.DisplayText, w);
    e.Bounds.Inflate(-2, -2);
}

More References:
How to put icons in grid cells
How to display external images in grid columns if the data source only contains links to the images
RepositoryItemPictureEdit Load Image
How to load a picture into the repositoryitemPictureEdit
RepositoryItemPictureEdit default empty image