• DateGridView标题列头添加复选框


    第一:添加列标题时,添加两个空格——用于显示复选框;

    第二:实现列标题添加复选框,代码如下:

    private void AddCheckeBoxToDGVHeader(DataGridView dgv)
            {
                for (int i = 0; i < this.dgvList.Columns.Count; i++)
                {
                    System.Windows.Forms.CheckBox ckBox = new System.Windows.Forms.CheckBox();
                    //ckBox.Text = "全选";
                    ckBox.Checked = true;
                    System.Drawing.Rectangle rect =
                        dgv.GetCellDisplayRectangle(i, -1, false);
                    ckBox.Size = new System.Drawing.Size(25, 25);
    
                    ckBox.Location = rect.Location;
                    ckBox.Padding = new System.Windows.Forms.Padding(2, 6, 0, 0);
                    ckBox.BackColor = Color.Transparent;
                    ckBox.Name = dgv.Columns[i].Name;
                    ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
    
                    dgv.Controls.Add(ckBox);
                }
            }
    
       void ckBox_CheckedChanged(object sender, EventArgs e)
            {
                CheckBox chb = sender as CheckBox;
                MessageBox.Show("Test=="+ chb.Name);
            }  
    

    运行效果如下:

  • 相关阅读:
    [Luogu1126] 机器人搬重物
    [POJ1830] 开关问题
    [bzoj3139] 比赛
    [POJ3349] Snowflake Snow Snowflakes
    The Tour
    [POJ3740] Easy Finding
    [vijos1453] 曼哈顿距离
    [POJ1632] Vase collection
    Codewars笔记
    Appium知识积累
  • 原文地址:https://www.cnblogs.com/YYkun/p/9186949.html
Copyright © 2020-2023  润新知