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

DevExpress中GridControl列本義的完成辦法

編輯:C#入門知識

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


在一些項目標現實開辟進程中,我們有時刻須要對GridControl中列值停止本義,比方1本義成“完成”等等,普通在諸如CustomColumnDisplayText事宜中可以或許輕松完成,為了進步代碼復用性,所以須要對CustomColumnDisplayText停止包裝。詳細辦法以下:

重要功效代碼以下:

/// <summary>
/// CustomColumnDisplayText Helper
/// </summary>
/// <param name="girdview">GridView</param>
/// <param name="fieldNameHandler">拜托</param>
/// <param name="dispalyTextHandler">展示文字</param>
/// <param name="e">CustomColumnDisplayTextEventArgs</param>
public static void CusColDisplayTextHelper(this GridView 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">拜托</param>
/// <param name="dispalyTextHandler">拜托</param>
/// <param name="e">CustomColumnDisplayTextEventArgs</param>
public static void CusColDisplayTextHelper(this GridView 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">拜托</param>
/// <param name="curdispalyText">展示文字</param>
/// <param name="e">CustomColumnDisplayTextEventArgs</param>
public static void CusColDisplayTextHelper(this GridView girdview, Func<object, Type, bool> valueHandler, string curdispalyText, CustomColumnDisplayTextEventArgs e)
{
  if (valueHandler(e.Value, e.Value.GetType()))
  {
 e.DisplayText = curdispalyText;
  }
}

代碼應用辦法以下:

private void gvLampConfig_CustomColumnDisplayText(object sender, CustomColumnDisplayTextEventArgs e)
{
  gvLampConfig.CusColDisplayTextHelper(name => name.Equals("LampViDirection"), value => value.ToInt(1) == 1 ? "正向" : "反向", e);
  gvLampConfig.CusColDisplayTextHelper(name => name.Equals("LampWorkStatus"), TranLampWorkType, e);
  gvLampConfig.CusColDisplayTextHelper(name => name.Equals("CTUChNo"), value => string.Format("第{0}回路", 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), "不修正", e);
}
private string TranLampDeviceType(object type)
{
  int _type = type.ToInt(-1);
  if (_type == 1) return "鈉燈";
  if (_type == 2) return "LED燈";
  if (_type == 3) return "無極燈";
  return "--";
}
private string TranLampPhase(object type)
{
  int _type = type.ToInt(-1);
  if (_type == 0) return "未知";
  if (_type == 1) return "A相";
  if (_type == 2) return "B相";
  if (_type == 3) return "C相";
  return "--";
}
private string TranLampWorkType(object type)
{
  int _type = type.ToInt(-1);
  if (_type == 0) return "封閉但不刪除";
  if (_type == 1) return "啟用";
  if (_type == 2) return "刪除";
  return "--";
}

代碼運轉後果以下所示:

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