2010年3月19日 星期五

Devexpress's XtraGrid 客制顯示圖檔

1. 設定要顯示圖檔的欄位屬性
    FieldName 設為 "Image" 或其它值, 只要與其它的欄位值不相同就好
    UnboundType 設為 Object
    ColumnEdit 選擇 RepositoryItemPictureEdit 元件 (支援 Image 顯示)

2. 設定 XtraGrid 的 CustomUnboundColumnData Event Method

3. 在 CustomUnboundColumnData Method 內做處理
    Ex.
if (e.Column.FieldName == "Image" && e.IsGetData) { GridView view = sender as GridView; //取資料列欄位Path值 string path = (string)view.GetRowCellValue(e.RowHandle, "Path"); //取資料列欄位PhotoName值 string photoName = (string)view.GetRowCellValue(e.RowHandle, "PhotoName"); string photoNamePath = path + photoName; if (!Images.ContainsKey(photoNamePath)) { Image img = Image.FromFile(photoNamePath); Images.Add(photoNamePath, img); } e.Value = Images[photoNamePath];               }
4. 此方式將可以客制欄位的輸出值

沒有留言:

張貼留言