轉(zhuǎn)帖|使用教程|編輯:龔雪|2014-03-27 15:20:06.000|閱讀 2002 次
概述:本文主要介紹在DevExpress GridView的列表中,如何使用圖片來快速顯示該記錄是否包含附件。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
如下界面所示:
但有時(shí)我們?cè)诹斜碇姓故局饕臄?shù)據(jù)的時(shí)候,我們希望知道哪一條記錄是否包含附件,以便我們快速查看相關(guān)的附件的時(shí)候,如下所示的展示效果,我們需要怎么做呢?
首先我們?cè)诮壎〝?shù)據(jù)操作中增加一個(gè)字段列,用來在GridView列表中進(jìn)行展示是否有附件的圖標(biāo)的,我們定義為 HasAttachment,然后判斷附件列表中是否存在附件,并賦值給存在附件的列,具體邏輯代碼如下所示。
/// <summary> /// 綁定列表數(shù)據(jù) /// </summary> public void BindData() { //entity this.winGridViewPager1.DisplayColumns = "Seq,Category,Title,HasAttachment"; #region 添加別名解析 this.winGridViewPager1.AddColumnAlias("Seq", "序號(hào)"); this.winGridViewPager1.AddColumnAlias("Category", "科研情況類別"); this.winGridViewPager1.AddColumnAlias("Title", "標(biāo)題信息"); this.winGridViewPager1.AddColumnAlias("AttachGUID", "附件GUID"); this.winGridViewPager1.AddColumnAlias("HasAttachment", "附件信息"); #endregion string where = GetConditionSql(); DataTable dt = WHC.Framework.ControlUtil.BLLFactory<StaffResearch>.Instance.FindToDataTable(where); if (dt != null) { dt.Columns.Add("HasAttachment", typeof(Image)); foreach (DataRow dr in dt.Rows) { string attachGUID = dr["AttachGUID"].ToString(); Dictionary<string, string> list = WHC.Framework.ControlUtil.BLLFactory<WHC.Attachment.BLL.FileUpload>.Instance.GetFileNames(attachGUID); if (list.Count > 0) { dr["HasAttachment"] = WHC.StaffData.Properties.Resources.attach2; } } } this.winGridViewPager1.DataSource = dt; this.winGridViewPager1.PrintTitle = "人員科研情況信息報(bào)表"; }
然后我們就是需要在GridView顯示的時(shí)候,進(jìn)行一些處理工作,如定義這個(gè)HasAttachment列的顯示類型,并限定它的寬度等操作,以便進(jìn)行更好的展示,如下代碼所示。
this.winGridViewPager1.gridView1.DataSourceChanged += new EventHandler(gridView1_DataSourceChanged);
/// <summary> /// 綁定數(shù)據(jù)后,分配各列的寬度 /// </summary> private void gridView1_DataSourceChanged(object sender, EventArgs e) { if (this.winGridViewPager1.gridView1.Columns.Count > 0 && this.winGridViewPager1.gridView1.RowCount > 0) { this.winGridViewPager1.gridView1.Columns["Seq"].Width = 50; this.winGridViewPager1.gridView1.Columns["Category"].Width = 50; this.winGridViewPager1.gridView1.Columns["Title"].Width = 200; RepositoryItemPictureEdit pic = new RepositoryItemPictureEdit(); pic.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom; pic.NullText = " "; pic.BestFitWidth = 80; this.winGridViewPager1.gridView1.Columns["HasAttachment"].ColumnEdit = pic; this.winGridViewPager1.gridView1.Columns["HasAttachment"].MaxWidth = 100; this.winGridViewPager1.gridView1.Columns["HasAttachment"].MinWidth = 80; } }
完成上面的幾步操作,我們就能在GridView中正常顯示一個(gè)圖標(biāo)了,通過這個(gè)案例,我們拓展開來,可以在GridView中展示更好的效果,例如可以把一些字段的Image圖形數(shù)據(jù)讀取出來并展示出來等操作。
轉(zhuǎn)載自//www.cnblogs.com/wuhuacong/p/3446168.html
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)