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

DevExpress完成GridControl同步列頭checkbox與列中checkbox狀況

編輯:C#入門知識

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


本文實例展現了DevExpress完成GridControl同步列頭checkbox與列中checkbox狀況的辦法,有必定的適用價值,詳細辦法以下:

重要功效代碼以下:

/// <summary>
/// 同步列頭checkbox與列中checkbox狀況
/// </summary>
/// <param name="view">GridView</param>
/// <param name="fieldeName">須要繪制Checkbox的列名</param>
/// <param name="e">MouseEventArgs</param>
public static void SyncCheckStatus(this GridView view, string fieldeName, MouseEventArgs e)
{
  /*解釋:
   *在MouseDown事宜中應用
   *參考:https://www.devexpress.com/Support/Center/Question/Details/Q354489
   *eg:
   *private void gvLampConfig_MouseDown(object sender, MouseEventArgs e)
   *{
   *GridView _view = sender as GridView;
   *_view.SyncCheckStatus(gcCheckFieldName, e);
   *}
   */
  if (e.Clicks == 1 && e.Button == MouseButtons.Left)
  {
 view.ClearSorting();
 view.PostEditor();
 GridHitInfo _info;
 Point _pt = view.GridControl.PointToClient(Control.MousePosition);
 _info = view.CalcHitInfo(_pt);
 if (_info.InColumn && _info.Column.FieldName.Equals(fieldeName))
 {
   if (getCheckedCount(view, fieldeName) == view.DataRowCount)
 UnChekAll(view, fieldeName);
   else
 CheckAll(view, fieldeName);
 }
  }
}
private static int getCheckedCount(GridView view, string filedName)
{
  int count = 0;
  for (int i = 0; i < view.DataRowCount; i++)
  {
 object _cellValue = view.GetRowCellValue(i, view.Columns[filedName]);
 //if (_cellValue != null && !(_cellValue is DBNull))
 if (_cellValue == null) continue;
 if (string.IsNullOrEmpty(_cellValue.ToString().Trim())) continue;
 bool _checkStatus = false;
 if (bool.TryParse(_cellValue.ToString(), out _checkStatus))
 {
   //if ((bool)_cellValue)
   if (_checkStatus)
 count++;
 }
  }
  return count;
}
private static void CheckAll(GridView view, string fieldName)
{
  for (int i = 0; i < view.DataRowCount; i++)
  {
 view.SetRowCellValue(i, view.Columns[fieldName], true);
  }
}
private static void UnChekAll(GridView view, string fieldName)
{
  for (int i = 0; i < view.DataRowCount; i++)
  {
 view.SetRowCellValue(i, view.Columns[fieldName], false);
  }
}

代碼應用辦法以下:

private void gvLampConfig_MouseDown(object sender, MouseEventArgs e)
{
  GridView _view = sender as GridView;
  _view.SyncCheckStatus(gcCheckFieldName, e);
}

代碼運轉後果以下:

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