Select All GridControl columns and check boxes, and select all gridcontrol columns.

Source: Internet
Author: User

Select All GridControl columns and check boxes, and select all gridcontrol columns.

Note:

Add a column to GirdControl. This column is not written in the database, but added in the code.

Figure:

 

Underlying class code:

# Region GridControl select all /// <summary> /// check whether selected /// </summary> private static bool chkState = false; // check box column name private static string chkFileName = ""; // check box column width private static int chkWidth = 30; // GridView public static DevExpress. xtraGrid. views. grid. gridView GView = null; private DevExpress. xtraGrid. views. grid. gridView gView {get {if (GView = null) {GView = new DevExpress. xtraGrid. views. grid. gridVi Ew ();} return GView;} set {this. gView = value ;}} public static void GridCheckEdit (DevExpress. xtraGrid. views. grid. gridView gv, string checkFileName, int checkWidth) {if (gv! = Null) {chkFileName = checkFileName; chkWidth = checkWidth; GView = gv; // do not display the column title gv of the check box. columns [chkFileName]. optionsColumn. showCaption = false; // the shape of the check box gv. columns [chkFileName]. the ColumnEdit instance is repositoryItemCheckEdit1 // repositoryItemCheckEdit1.CheckStyle = DevExpress. xtraEditors. controls. checkStyles. standard; // check box loading status solid hollow tick // repositoryItemCheckEdit1.NullStyle = DevExpress. xtraEditors. co Ntrols. styleIndeterminate. unchecked; // Click Event gv. click + = new System. eventHandler (gv_Click); // draws the column header CheckEdit gv. customDrawColumnHeader + = new DevExpress. xtraGrid. views. grid. columnHeaderCustomDrawEventHandler (gv_CustomDrawColumnHeader); gv. performancechanged + = new EventHandler (gv_performancechanged) ;}} private static void gv_Click (object sender, EventArgs e) {if (ClickGridCheckBox (GView, chkFileName, ChkState) {chkState =! ChkState ;}} private static void gv_CustomDrawColumnHeader (object sender, DevExpress. XtraGrid. Views. Grid. ColumnHeaderCustomDrawEventArgs e) {if (e. Column! = Null & e. column. fieldName = chkFileName) {e. info. innerElements. clear (); e. painter. drawObject (e. info); DrawCheckBox (e, chkState); e. handled = true ;}} private static void gv_performancechanged (object sender, EventArgs e) {DevExpress. xtraGrid. columns. gridColumn column = GView. columns. columnByFieldName (chkFileName); if (column! = Null) {column. width = chkWidth; column. optionsColumn. showCaption = false; column. columnEdit = new DevExpress. xtraEditors. repository. repositoryItemCheckEdit () ;}} private static void DrawCheckBox (DevExpress. xtraGrid. views. grid. columnHeaderCustomDrawEventArgs e, bool chk) {DevExpress. xtraEditors. repository. repositoryItemCheckEdit repositoryCheck = e. column. columnEdit as DevExpress. xtraEditors. re Pository. RepositoryItemCheckEdit; if (repositoryCheck! = Null) {System. drawing. graphics g = e. graphics; System. drawing. rectangle r = e. bounds; DevExpress. xtraEditors. viewInfo. checkEditViewInfo info; DevExpress. xtraEditors. drawing. checkEditPainter painter; DevExpress. xtraEditors. drawing. controlGraphicsInfoArgs args; info = repositoryCheck. createViewInfo () as DevExpress. xtraEditors. viewInfo. checkEditViewInfo; painter = repositoryCheck. createPainter () DevExpress. xtraEditors. drawing. checkEditPainter; info. editValue = chk; info. bounds = r; info. calcViewInfo (g); args = new DevExpress. xtraEditors. drawing. controlGraphicsInfoArgs (info, new DevExpress. utils. drawing. graphicsCache (g), r); painter. draw (args); args. cache. dispose () ;}} private static bool ClickGridCheckBox (DevExpress. xtraGrid. views. grid. gridView gridView, string fieldName, bool currentSt Atus) {bool result = false; if (gridView! = Null) {// forbid sorting the gridView. clearSorting (); gridView. postEditor (); DevExpress. xtraGrid. views. grid. viewInfo. gridHitInfo info; System. drawing. point pt = gridView. gridControl. pointToClient (Control. mousePosition); info = gridView. calcHitInfo (pt); if (info. inColumn & info. column! = Null & info. column. fieldName = fieldName) {for (int I = 0; I <gridView. rowCount; I ++) {gridView. setRowCellValue (I, fieldName ,! CurrentStatus) ;}return true ;}} return result ;}# endregion

 

Foreground call:

Note: Before GridControl is bound, manually add a column. After adding a column, bind the column.

// Add a column of dt. columns. add ("chk", System. type. getType ("System. boolean "); dt. columns ["chk"]. defaultValue = Boolean. falseString; gridControl1.DataSource = dt; Functionjsj. gridCheckEdit (gv, "chk", 50 );

Chk legend:

 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.