datagridview表头天剑复选框

datagridview表头天剑复选框
 private void User_Form_Load(object sender, EventArgs e)
        {
            winPagesImage1.ShowWhat = ShowWhat;
            winPagesImage1.PageSize = Pagesize; 
            int allcount = 0;
            winPagesImage1.NowPage = 1;
            dbu.SearchUsersCompleted += new Ha_Demo.DBUser.SearchUsersCompletedEventHandler(dbu_SearchUsersCompleted);
            dbu.SearchUsersAsync(Where, Field, OrderBy, Pagesize.ToString(), "1", allcount);
            pictureBox1.Visible = true;

            winPagesImage1.dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft;
            winPagesImage1.dataGridView1.DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopLeft;
            System.Windows.Forms.CheckBox ckBox = new System.Windows.Forms.CheckBox();
            ckBox.Text = "全选";
            ckBox.Checked = false;
            System.Drawing.Rectangle rect = winPagesImage1.dataGridView1.GetCellDisplayRectangle(5, -1, true);
            ckBox.Size = new System.Drawing.Size(winPagesImage1.dataGridView1.Columns[5].Width, 20); 
            ckBox.Location = rect.Location; 
            ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
            winPagesImage1.dataGridView1.Controls.Add(ckBox);
        }
        void ckBox_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < winPagesImage1.dataGridView1.Rows.Count; i++)
            {
                winPagesImage1.dataGridView1.Rows[i].Cells[5].Value = ((System.Windows.Forms.CheckBox)sender).Checked;
            }
            winPagesImage1.dataGridView1.EndEdit();
        }  
datagridview表头天剑复选框

datagridview表头天剑复选框

上一篇:vue整合微信支付


下一篇:实现DataGridView控件中CheckBox列的使用