[WinForm] [DevExpress] [Gridcontrol] Customcolumndisplaytext Helper

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.