GridControl的一列中显示图片
- 软件设计
- 2025-03-24
- 126

设置标题FieldName设为 PhotoColumnEdit设为RepositoryItemPictureEdit类UnboundType设为 UnboundColu...
设置标题FieldName设为 Photo
ColumnEdit设为RepositoryItemPictureEdit类
UnboundType设为 UnboundColumnType.Object
代码
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column.FieldName == "Photo" && e.IsGetData)
{
//RefImage是存储图片路径的那一列
string filePath = (string)((DataRowView)e.Row)["图片地址"];
Image img = null;
try
{
//判断图片路径是否为网络路径
if (PublicGetConnect.UrlDiscern(filePath)==true)
{
//文件是否存在
if (PublicGetConnect.RemoteFileExists(filePath))
{
//读取文件
using (WebClient wc = new WebClient())
{
img = new Bitmap(wc.OpenRead(filePath));
}
}
}
// 判断本地文件是否存在
else if (PublicGetConnect.LocalFileExists(filePath))
{
//加载本地图片
img = Image.FromFile(filePath);
}
//pictureEdit列绑定图片
e.Value = img;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
本文链接:http://zxmcloud.com/?id=94
发表评论