轉(zhuǎn)帖|使用教程|編輯:龔雪|2017-01-09 13:40:10.000|閱讀 1286 次
概述:
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在DevExpress GridView里面需要呈現(xiàn)圖片,圖片在數(shù)據(jù)庫里面儲存的是文件名。
如果大家想要使用PictureEdit來呈現(xiàn),那么下面是一個(gè)小技巧:
1. 新建一個(gè)FieldName為Image的column;
2. UnBoundType選擇Object,ColumnEdit使用PictureEdit;
3. 通過 gridView1_CustomUnboundColumnData來實(shí)現(xiàn)。具體代碼如下:
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使用技巧?海量視頻課程以及最專業(yè)的DevExpress培訓(xùn)盡在。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn