日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GridControl 选择列、复选框全选(上)

發布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GridControl 选择列、复选框全选(上) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

說明:

??? GirdControl 中加入一列,這一列不是寫在數據庫中的,而是代碼中加入的。

圖示:

?

底層類代碼:

#region GridControl 全選/// <summary>/// 是否選中/// </summary>private static bool chkState = false;//復選框列名稱private static string chkFileName = "";//復選框列寬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.GridView();}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;//不顯示復選框的列標題gv.Columns[chkFileName].OptionsColumn.ShowCaption = false;//復選框的形狀 gv.Columns[chkFileName].ColumnEdit 實例是 repositoryItemCheckEdit1 //repositoryItemCheckEdit1.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.Standard;復選框載入的狀態 實心 空心 空心打勾//repositoryItemCheckEdit1.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;//點擊事件gv.Click += new System.EventHandler(gv_Click);//畫列頭CheckEditgv.CustomDrawColumnHeader += new DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventHandler(gv_CustomDrawColumnHeader);gv.DataSourceChanged += new EventHandler(gv_DataSourceChanged);}}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_DataSourceChanged(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.Repository.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() as 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 currentStatus){bool result = false;if (gridView != null){//禁止排序 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

?

前臺調用:

注意:GridControl綁定前。手動添加一列。添加完畢之后,在綁定。

//加入一列dt.Columns.Add("chk", System.Type.GetType("System.Boolean"));dt.Columns["chk"].DefaultValue = Boolean.FalseString;gridControl1.DataSource = dt;Functionjsj.GridCheckEdit(gv, "chk", 50);

chk 圖例:

?

轉載于:https://www.cnblogs.com/jzssuanfa/p/6795660.html

總結

以上是生活随笔為你收集整理的GridControl 选择列、复选框全选(上)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。