DataGridview 全选框

#region 建立全选 CheckBox For gridDnList

//建立个矩形,等下计算 CheckBox 嵌入 GridView 的位置
Rectangle rect = gridDnList.GetCellDisplayRectangle(0, -1, true);
rect.Size = new Size(18, 18);
rect.X = rect.Location.X + rect.Width / 4 + 6;
rect.Y = rect.Location.Y + (rect.Height / 2 - 9) + 6;

CheckBox cbHeader = new CheckBox();
cbHeader.BackColor = System.Drawing.Color.Transparent;
cbHeader.UseVisualStyleBackColor = false;
cbHeader.Name = "checkboxHeader";
cbHeader.Size = new Size(18, 18);
cbHeader.Location = rect.Location;
//全选事件
cbHeader.CheckedChanged += new EventHandler(cbHeader_CheckedChanged);

//将 CheckBox 加入到 dataGridView
gridDnList.Controls.Add(cbHeader);

#endregion

posted @ 2022-11-28 15:05  孤夏  阅读(215)  评论(0编辑  收藏  举报