[WinForm] [DevExpress] Custom button text content in GridControl

Source: Internet
Author: User

Recently, the FindPanel of GridControl is used in project development. This allows you to filter data, but the displayed button text is in English,

Public class BuilderGridLocalizer: GridLocalizer {Dictionary <GridStringId, string> CusLocalizedKeyValue = null; /// <summary> /// constringid with parameters /// </summary> /// <param name = "cusLocalizedKeyValue"> GridStringId to be transferred, the corresponding text description </param> public BuilderGridLocalizer (Dictionary <GridStringId, string> cusLocalizedKeyValue) {CusLocalizedKeyValue = cusLocalizedKeyValue ;} /// <summary> /// heavy load /// </summary> /// <Param name = "id"> GridStringId </param> // <returns> string </returns> public override string GetLocalizedString (GridStringId) {if (CusLocalizedKeyValue! = Null) {string _ gridStringDisplay = string. empty; foreach (KeyValuePair <GridStringId, string> gridLocalizer in CusLocalizedKeyValue) {if (gridLocalizer. key. equals (id) {_ gridStringDisplay = gridLocalizer. value; break ;}} return _ gridStringDisplay;} return base. getLocalizedString (id );}}

Define a class to inherit GridLocalizer and override the GetLocalizedString method. The logic is very simple. To make it easier to reuse code and reduce repeated encoding, add a method to another class, as shown below:
/// <Summary> /// custom GridControl button text /// </summary> /// <param name = "girdview"> GridView </param> /// <param name = "cusLocalizedKeyValue"> GridStringId to be transferred, the corresponding text description </param> public static void CustomButtonText (this GridView girdview, Dictionary <GridStringId, string> cusLocalizedKeyValue) {comment _ bGridLocalizer = new comment (cusLocalizedKeyValue); GridLocalizer. active = _ bGridLocalizer ;}

The Code is as follows:

Private Dictionary <GridStringId, string> SetGridLocalizer () {Dictionary <GridStringId, string> _ gridLocalizer = new Dictionary <GridStringId, string> (); _ gridLocalizer. add (GridStringId. findControlFindButton, "Search"); _ gridLocalizer. add (GridStringId. findControlClearButton, "clear"); return _ gridLocalizer;} private void Form1_Load (object sender, EventArgs e) {Dictionary <GridStringId, string> _ gridLocalizer = SetGridLocalizer (); gridView1.CustomButtonText (_ gridLocalizer); gridControl1.DataSource = CreateTable (20); gridView1.ShowFindPanel ();}

Code effect:

. Csharpcode ,. csharpcode pre {font-size: small; color: black; font-family: Las LAS, "Courier New", courier, monospace; background-color: # ffffff; /* white-space: pre ;*/}. csharpcode pre {margin: 0em ;}. csharpcode. rem {color: #008000 ;}. csharpcode. kwrd {color: # 0000ff ;}. csharpcode. str {color: #006080 ;}. csharpcode. op {color: # effecc0 ;}. csharpcode. preproc {color: # cc6633 ;}. csharpcode. asp {background-color: # ffff00 ;}. csharpcode. html {color: #800000 ;}. csharpcode. attr {color: # ff0000 ;}. csharpcode. alt {background-color: # f4f4f4; width: 100%; margin: 0em ;}. csharpcode. lnum {color: #606060 ;}

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.