在DevExpress GridView里面需要呈现图片,图片在数据库里面储存的是文件名。
如果大家想要使用PictureEdit来呈现,那么下面是一个小技巧:
1. 新建一个FieldName为Image的column;
2. UnBoundType选择Object,ColumnEdit使用PictureEdit;
3. 通过 gridView1_CustomUnboundColumnData来实现。具体代码如下:
string _imageDir = @"Photos\"; Hashtable _images = new Hashtable(); private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) { if (e.Column.FieldName == "Image" && e.IsGetData) { GridView view = sender as GridView; string fileName = (string)view.GetRowCellValue(e.ListSourceRowIndex, "PhotoPath"); if (!_images.ContainsKey(fileName)) { Image img = null; try { string filePath = DevExpress.Utils.FilesHelper.FindingFileName(Application.StartupPath, _imageDir + fileName, false); img = Image.FromFile(filePath); } string filePath = DevExpress.Utils.FilesHelper.FindingFileName(Application.StartupPath, _imageDir + fileName, false); img = Image.FromFile(filePath); } catch { } _images.Add(fileName, img); } e.Value = _images[fileName]; } }
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/917.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/917.html