In real-world development, it is sometimes necessary to escape the column values in the Gridcontrol, such as 1 escape to completion, and so on, in general, such as the Customcolumndisplaytext event can be easily done, in order to improve code reusability, So the Customcolumndisplaytext is packaged.
Key code:
// <summary> /// Customcolumndisplaytext Helper // </summary> /// <param name= "Girdview" >GridView</param> /// <param name= "Fieldnamehandler" > delegation </param> /// <param name= "Dispalytexthandler" > Show text </param> /// <param name= "E" >CustomColumnDisplayTextEventArgs</param> Public Static voidCuscoldisplaytexthelper ( ThisGridView Girdview, predicate<string> Fieldnamehandler, func<Object,string> Dispalytexthandler, Customcolumndisplaytexteventargs e) {if(Fieldnamehandler (E.column.fieldname)) {E.displaytext = Dispalytexthandler (E.value); } }// <summary> /// Customcolumndisplaytext Helper // </summary> /// <param name= "Girdview" >GridView</param> /// <param name= "Valuehandler" > delegation </param> /// <param name= "Dispalytexthandler" > delegation </param> /// <param name= "E" >CustomColumnDisplayTextEventArgs</param> Public Static voidCuscoldisplaytexthelper ( ThisGridView Girdview, func<Object, Type,BOOL> Valuehandler, func<Object,string> Dispalytexthandler, Customcolumndisplaytexteventargs e) {if(Valuehandler (E.value, E.value.gettype ())) {E.displaytext = Dispalytexthandler (E.value); } }// <summary> ///customcolumndisplaytext Helper // </summary> /// <param name= "Girdview" >GridView</param> /// <param name= "Valuehandler" > delegation </param> /// <param name= "Curdispalytext" > Show text </param> /// <param name= "E" >CustomColumnDisplayTextEventArgs</param> Public Static voidCuscoldisplaytexthelper ( ThisGridView Girdview, func<Object, Type,BOOL> Valuehandler,stringCurdispalytext, Customcolumndisplaytexteventargs e) {if(Valuehandler (E.value, E.value.gettype ())) {e.displaytext = Curdispalytext; } }
Code use:
Private voidGvlampconfig_customcolumndisplaytext (Objectsender, Customcolumndisplaytexteventargs e) {gvlampconfig.cuscoldisplaytexthelper (name = = name). Equals ("Lampvidirection"),value=value. ToInt (1) = = 1?"Forward":"Reverse", e); Gvlampconfig.cuscoldisplaytexthelper (name = = name). Equals ("Lampworkstatus"), Tranlampworktype, E); Gvlampconfig.cuscoldisplaytexthelper (name = = name). Equals ("Ctuchno"),value=string. Format ("{0} loop",value), E); Gvlampconfig.cuscoldisplaytexthelper (name = = name). Equals ("Lampphase"), Tranlampphase, E); Gvlampconfig.cuscoldisplaytexthelper (name = = name). Equals ("Lampdevicetype"), Tranlampdevicetype, E); Gvlampconfig.cuscoldisplaytexthelper (name = = name). Equals ("Lamppower"),value=string. Format ("{0} W",value), E); Gvlampconfig.cuscoldisplaytexthelper (name = = name). Equals ("Lampintensity"),value=string. Format ("{0}%",value), E); Gvlampconfig.cuscoldisplaytexthelper ((value, type) = =value. ToInt ( -1) = =-1 && type = =typeof(Int32),"Do not modify", e); }Private stringTranlampdevicetype (ObjectType) {int_type = type. ToInt (-1);if(_type = = 1)return "Sodium lamp";if(_type = = 2)return "LED Light";if(_type = = 3)return "Electrodeless lamp";return "--"; }Private stringTranlampphase (ObjectType) {int_type = type. ToInt (-1);if(_type = = 0)return "Unknown";if(_type = = 1)return "A-phase";if(_type = = 2)return "B-Phase";if(_type = = 3)return "C-Phase";return "--"; }Private stringTranlampworktype (ObjectType) {int_type = type. ToInt (-1);if(_type = = 0)return "Close without deleting";if(_type = = 1)return "Enabled";if(_type = = 2)return "Delete";return "--"; }
Code effects:
Hope to be helpful!