?
為了測試方便,我們加入新的3列,格式分別是數據,時間,字符串。代碼增加下列部分:
[csharp] view plaincopyprint?
??dt.Columns.Add("數據",typeof(decimal));??dt.Columns.Add("時間",typeof(DateTime));??dt.Columns.Add("自定義",typeof(string));??dt.Rows.Add(new?object[]?{?1,?"張三",?1,"東大街6號","看書","",-52.874,"2011-8-5?17:52:55","###"?});??dt.Rows.Add(new?object[]?{?1,?"王五",?0,"西大街2號","上網,游戲","",?-37.257,"2011-8-5?17:52:55"?});??dt.Rows.Add(new?object[]?{?1,?"李四",?1,"南大街3號","上網,逛街","",?-54.254,"2011-8-9?17:52:55"?});??dt.Rows.Add(new?object[]?{?1,?"錢八",?0,"北大街5號","上網,逛街,看書,游戲","",-35.127,"2011-8-9?17:52:55"?});??dt.Rows.Add(new?object[]?{?1,"趙九",?1,"中大街1號","看書,逛街,游戲","",-29.548,"2011-8-9?20:52:55"?});?? //格式增加
dt.Columns.Add("數據",typeof(decimal));
dt.Columns.Add("時間",typeof(DateTime));
dt.Columns.Add("自定義",typeof(string));
dt.Rows.Add(new object[] { 1, "張三", 1,"東大街6號","看書","",-52.874,"2011-8-5 17:52:55","###" });
dt.Rows.Add(new object[] { 1, "王五", 0,"西大街2號","上網,游戲","", -37.257,"2011-8-5 17:52:55" });
dt.Rows.Add(new object[] { 1, "李四", 1,"南大街3號","上網,逛街","", -54.254,"2011-8-9 17:52:55" });
dt.Rows.Add(new object[] { 1, "錢八", 0,"北大街5號","上網,逛街,看書,游戲","",-35.127,"2011-8-9 17:52:55" });
dt.Rows.Add(new object[] { 1,"趙九", 1,"中大街1號","看書,逛街,游戲","",-29.548,"2011-8-9 20:52:55" });
給gridControl1增加3列,對應上述三列。
數據:
具體數據公式可以查看輸入控件的MASK設置器,里面有全部的格式公式:
運行結果:
時間:
自定義:
事件轉換:
概念明確:
1.??????gridControl1的每一列原始數據是Value,但是顯示數據是 DisplayText,默認DisplayText的值即是Value通過DisplayFormat轉換之后的值。
2.??????gridControl下的事件一般是包含表格GridView切換,點擊,更改的事件,用的不多;每一個GridView下的事件包含行列處理,菜單顯示,分組排序等事件,我們常用。(所有在使用事件時,一定要明確是control事件還是view事件)
GridView存在事件:自定義列顯示事件
增加事件:
[csharp] view plaincopyprint?
private?voidgridView1_CustomColumnDisplayText(objectsender,?DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgse)??????????{??????????????if(e.Column.FieldName?=="sex")??????????????{??????????????????switch(e.Value.ToString().Trim())??????????????????{??????????????????????case"1":??????????????????????????e.DisplayText?=?"男";??????????????????????????break;??????????????????????case"0":??????????????????????????e.DisplayText?=?"女";??????????????????????????break;??????????????????????default:??????????????????????????e.DisplayText?=?"";??????????????????????????break;???????????????????}???????????????}???????????}?? private voidgridView1_CustomColumnDisplayText(objectsender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgse){if(e.Column.FieldName =="sex"){switch(e.Value.ToString().Trim()){case"1":e.DisplayText = "男";break;case"0":e.DisplayText = "女";break;default:e.DisplayText = "";break;}}}
顯示結果:
轉載于:https://www.cnblogs.com/lteal/archive/2012/12/28/2836925.html
總結
以上是生活随笔為你收集整理的GridControl详解(三)列数据的格式设置的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。