Key code:
/// <Summary> /// draw CheckBox for the column header // </summary> /// <param name = "view"> GridView </param> /// <param name = "checkItem"> RepositoryItemCheckEdit </param> /// <param name = "fieldName"> name of the Checkbox column to be drawn </param> /// <param name = "e"> ColumnHeaderCustomDrawEventArgs </param> public static void DrawHeaderCheckBox (this GridView view, repositoryItemCheckEdit checkItem, string fieldName, ColumnHeaderCustomDrawEventArgs e) {/* Description: * Reference: https://www.devexpress.com/Support/Center/Question/Details/Q354489 * Use ** eg: * private void gvCabChDetail_CustomDrawColumnHeader (object sender, DevExpress. xtraGrid. views. grid. columnHeaderCustomDrawEventArgs e) * {* GridView _ view = sender as GridView; * _ view. drawHeaderCheckBox (CheckItem, "Check", e); *} */if (e. column! = Null & e. column. fieldName. equals (fieldName) {e. info. innerElements. clear (); e. painter. drawObject (e. info); DrawCheckBox (checkItem, e. graphics, e. bounds, getCheckedCount (view, fieldName) = view. dataRowCount); e. handled = true ;}} private static void DrawCheckBox (checking checkItem, Graphics g, Rectangle r, bool Checked) {CheckEditViewInfo _ info; CheckEditPainter _ painter; ControlGraphicsInfoArgs _ args; _ info = checkItem. createViewInfo () as CheckEditViewInfo; _ painter = checkItem. createPainter () as CheckEditPainter; _ info. editValue = Checked; _ info. bounds = r; _ info. paintAppearance. foreColor = Color. black; _ info. calcViewInfo (g); _ args = new ControlGraphicsInfoArgs (_ info, new DevExpress. utils. drawing. graphicsCache (g), r); _ painter. draw (_ args); _ args. cache. dispose ();} 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) continue; if (string. isNullOrEmpty (_ cellValue. toString (). trim () continue; bool _ checkStatus = false; if (bool. tryParse (_ cellValue. toString (), out _ checkStatus) {if (_ checkStatus) count ++ ;}} return count ;}
Code usage:
RepositoryItemCheckEdit CheckItem = new RepositoryItemCheckEdit(); const string gcCheckFieldName = "Checked"; private void gvLampConfig_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e) { GridView _view = sender as GridView; _view.DrawHeaderCheckBox(CheckItem, gcCheckFieldName, e); }
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 ;}