程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> DevExpress完成自界說GridControl中按鈕文字內容的辦法

DevExpress完成自界說GridControl中按鈕文字內容的辦法

編輯:C#入門知識

DevExpress完成自界說GridControl中按鈕文字內容的辦法。本站提示廣大學習愛好者:(DevExpress完成自界說GridControl中按鈕文字內容的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是DevExpress完成自界說GridControl中按鈕文字內容的辦法正文


在一些C#項目標開辟中,有時刻會應用到GridControl的FindPanel,如許可以很好的對數據停止挑選,可是所展示的按鈕文字是英文,以下圖所示:

那怎樣界說兩個按鈕成績,以相符項目需求了?本文講述應用GridLocalizer來完成這一請求的辦法。詳細步調以下:

重要功效代碼以下:

public class BuilderGridLocalizer : GridLocalizer
{
Dictionary<GridStringId, string> CusLocalizedKeyValue = null;
/// <summary>
/// 帶參數的結構函數
/// </summary>
/// <param name="cusLocalizedKeyValue">須要轉移的GridStringId,其對應的文字描寫</param>
public BuilderGridLocalizer(Dictionary<GridStringId, string> cusLocalizedKeyValue)
{
  CusLocalizedKeyValue = cusLocalizedKeyValue;
}
/// <summary>
/// 重載
/// </summary>
/// <param name="id">GridStringId</param>
/// <returns>string</returns>
public override string GetLocalizedString(GridStringId id)
{
  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);
}

}

界說一個類繼續GridLocalizer,重寫GetLocalizedString辦法,邏輯很簡略;為了今後能更簡略反復應用代碼,削減反復編碼,所以在別的一個類中添加一個辦法,以下:

/// <summary>
/// 自界說GridControl按鈕文字
/// </summary>
/// <param name="girdview">GridView</param>
/// <param name="cusLocalizedKeyValue">須要轉移的GridStringId,其對應的文字描寫</param>
public static void CustomButtonText(this GridView girdview, Dictionary<GridStringId, string> cusLocalizedKeyValue)
{
  BuilderGridLocalizer _bGridLocalizer = new BuilderGridLocalizer(cusLocalizedKeyValue);
  GridLocalizer.Active = _bGridLocalizer;
}
如許子我們可以很簡略應用,代碼以下:

private Dictionary<GridStringId, string> SetGridLocalizer()
{
  Dictionary<GridStringId, string> _gridLocalizer = new Dictionary<GridStringId, string>();
  _gridLocalizer.Add(GridStringId.FindControlFindButton, "查找");
  _gridLocalizer.Add(GridStringId.FindControlClearButton, "清空");
  return _gridLocalizer;
}
private void Form1_Load(object sender, EventArgs e)
{
  Dictionary<GridStringId, string> _gridLocalizer = SetGridLocalizer();
  gridView1.CustomButtonText(_gridLocalizer);
  gridControl1.DataSource = CreateTable(20);
  gridView1.ShowFindPanel();
}

代碼運轉後果以下圖所示:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved