[WinForm] [DevExpress] Customizing button text content in Gridcontrol

Source: Internet
Author: User

Recent project development, the use of Gridcontrol Findpanel, so that the data can be very good screening, but the display of the button text is in English,

So how do you define two button issues to match the project requirements? A search has found that using Gridlocalizer can be very well implemented:

Core code:

    Public classBuildergridlocalizer:gridlocalizer {dictionary<gridstringid,string> Cuslocalizedkeyvalue =NULL;// <summary>        /// constructor with parameters        // </summary>        /// <param name= "Cuslocalizedkeyvalue" > Need to transfer the GRIDSTRINGID, its corresponding text description </param>         PublicBuildergridlocalizer (Dictionary<gridstringid,string> Cuslocalizedkeyvalue) {cuslocalizedkeyvalue = Cuslocalizedkeyvalue; }// <summary>        /// heavy        // </summary>        /// <param name= "id" >GridStringId</param>        // <returns>string</returns>         Public Override stringGetlocalizedstring (Gridstringid ID) {if(Cuslocalizedkeyvalue! =NULL)            {string_gridstringdisplay =string. Empty;foreach(Keyvaluepair<gridstringid,string> GridlocalizerinchCuslocalizedkeyvalue) {if(GridLocalizer.Key.Equals (ID)) {_gridstringdisplay = Gridlocalizer.value; Break; }                }return_gridstringdisplay; }return Base.        Getlocalizedstring (ID); }    }
To define a class to inherit Gridlocalizer, overriding the Getlocalizedstring method, the logic is simple; to make it easier to reuse code later, to reduce the number of duplicate encodings, add a method to the other class as follows:
        // <summary>        ///   Custom Gridcontrol button text        // </summary>        /// <param name= "Girdview" >GridView</param>        /// <param name= "Cuslocalizedkeyvalue" > Need to transfer the GRIDSTRINGID, its corresponding text description </param>         Public Static void Custombuttontext (Thisstring> Cuslocalizedkeyvalue)        {            new Buildergridlocalizer (cuslocalizedkeyvalue);            gridlocalizer.active = _bgridlocalizer;        }

This way we can use it very simply, the code is as follows:

        PrivateDictionary<gridstringid,string> Setgridlocalizer () {dictionary<gridstringid,string> _gridlocalizer =NewDictionary<gridstringid,string> (); _gridlocalizer.add (Gridstringid.findcontrolfindbutton,"Find"); _gridlocalizer.add (Gridstringid.findcontrolclearbutton,"Empty");return_gridlocalizer; }Private voidForm1_Load (Objectsender, EventArgs e) {dictionary<gridstringid,string> _gridlocalizer = Setgridlocalizer ();            Gridview1.custombuttontext (_gridlocalizer);            Gridcontrol1.datasource = CreateTable (20);        Gridview1.showfindpanel (); }

Code effects:

Related Article

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.