Exemple #1
0
 void chkheadercell_OnCheckBoxClicked(object sender, DataGridViewCheckboxHeaderEventArgs e)
 {
     if (OnCheckedAllClick != null)
         OnCheckedAllClick(sender, e);
 }
Exemple #2
0
        /// <summary>
        /// 点击列头checkbox单击事件
        /// </summary>
        protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
        {
            Point point = new Point(e.X + cellLocation.X, e.Y + cellLocation.Y);

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

                //获取列头checkbox的选择状态

                DataGridViewCheckboxHeaderEventArgs args = new DataGridViewCheckboxHeaderEventArgs();
                args.CheckedState = isChecked;

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

                if (OnCheckBoxClicked != null)
                {
                    OnCheckBoxClicked(sender, args);//触发单击事件

                    try
                    {
                        if (this != null && this.DataGridView != null)
                        {
                            this.DataGridView.InvalidateCell(this); //列头checkbox无效,不能是Datagridview列无效

                            DataGridViewCell currentCell = this.DataGridView.CurrentCell;

                            this.DataGridView.CurrentCell = null;

                            if (currentCell != null)
                                this.DataGridView.CurrentCell = currentCell;
                        }
                    }
                    catch
                    {

                    }
                }
            }

            base.OnMouseClick(e);
        }
Exemple #3
0
        /// <summary>
        /// 单击事件
        /// </summary>
        private void ch_OnCheckBoxClicked(object sender, DataGridViewCheckboxHeaderEventArgs e)
        {
            foreach (DataGridViewRow row in BindDataGridView.Rows)
            {
                row.Cells[CheckAllColumnIndex].Value = e.CheckedState;
            }

            if (OnCheckBoxClicked != null)
                OnCheckBoxClicked(sender, e);
        }