/// <summary>
        /// 点击列头checkbox单击事件
        /// </summary>
        protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
        {
            Point p = new Point(e.X + _cellLocation.X, e.Y + _cellLocation.Y);

            if (p.X >= checkBoxLocation.X && p.X <=
                checkBoxLocation.X + checkBoxSize.Width &&
                p.Y >= checkBoxLocation.Y && p.Y <=
                checkBoxLocation.Y + checkBoxSize.Height)
            {
                _checked = !_checked;

                //获取列头checkbox的选择状态
                datagridviewCheckboxHeaderEventArgs ex = new datagridviewCheckboxHeaderEventArgs(e.ColumnIndex);
                ex.CheckedState = _checked;

                object sender = new object();//此处不代表选择的列头checkbox,只是作为参数传递。应该列头checkbox是绘制出来的,无法获得它的实例

                if (OnCheckBoxClicked != null)
                {
                    OnCheckBoxClicked(sender, ex);//触发单击事件
                    this.DataGridView.InvalidateCell(this);
                }
            }
            base.OnMouseClick(e);
        }
Ejemplo n.º 2
0
 private void ch_OnCheckBoxClicked(object sender, datagridviewCheckboxHeaderEventArgs e)
 {
     foreach (DataGridViewRow dgvRow in this.Rows)
     {
         dgvRow.Cells[e.ColumnIndex].Value = e.CheckedState;
     }
     this.Refresh();
 }
        /// <summary> 
        /// 点击列头checkbox单击事件 
        /// </summary> 
        protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
        {
            Point p = new Point(e.X + _cellLocation.X, e.Y + _cellLocation.Y);
            if (p.X >= checkBoxLocation.X && p.X <=
                checkBoxLocation.X + checkBoxSize.Width
            && p.Y >= checkBoxLocation.Y && p.Y <=
                checkBoxLocation.Y + checkBoxSize.Height)
            {
                _checked = !_checked;

                //获取列头checkbox的选择状态
                datagridviewCheckboxHeaderEventArgs ex = new datagridviewCheckboxHeaderEventArgs(e.ColumnIndex);
                ex.CheckedState = _checked;

                object sender = new object();//此处不代表选择的列头checkbox,只是作为参数传递。应该列头checkbox是绘制出来的,无法获得它的实例

                if (OnCheckBoxClicked != null)
                {
                    OnCheckBoxClicked(sender, ex);//触发单击事件
                    this.DataGridView.InvalidateCell(this);
                }
            }
            base.OnMouseClick(e);
        }
 private void ch_OnCheckBoxClicked(object sender, datagridviewCheckboxHeaderEventArgs e)
 {
     foreach (DataGridViewRow dgvRow in this.Rows)
     {
         dgvRow.Cells[e.ColumnIndex].Value = e.CheckedState;
     }
     this.Refresh();
 }