在XtraGrid中将图像设置为RepositoryItemPictureEdit

时间:2013-01-29 18:48:43

标签: repository devexpress xtragrid

我有XtraGrid,我添加了一个新列并将其ColumnEdit属性设置为RepositoryItemPictureEdit。 我曾尝试使用RepositoryItemPictureEdit1.Appearance.Image将图像设置为它,但是在表单加载后它没有填充,有什么想法吗?

我有2011版

1 个答案:

答案 0 :(得分:2)

因为我猜你没有以正确的方式分配图像来控制。您可以浏览此DevExpress KB主题 - Why do I get the "No image data" text in the GridColumn with the PictureEdit in-place editor?

来源:Assigning an image to a RepositoryItemPictureEdit
你也可以使用这种方法:
1)将列的FieldName属性设置为“Image”,因为DataTable包含此字段
2)将Image DataColumn类型设置为Image值
3)更改代码,不要将图像转换为字节数组。

只需将其设置如下:

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

pictureEdit.SizeMode = PictureSizeMode.Zoom;

pictureEdit.NullText = " ";

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

要使编辑器加载图像,基础数据类型应对应于RepositoryItemPictureEdit.PictureStoreMode属性值

如果要在单元格中显示图像,则可以使用CustomDrawCell事件

此处ImageStream是存储图片的属性。

 public Stream ImageStream { get; set; }

您可以按照以下方式使用它:

    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);
}

更多参考文献:
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