zoukankan      html  css  js  c++  java
  • dataGridView1 checkbox全选

      private void AddHeaderCheckBox()
            {
                HeaderCheckBox = new CheckBox();
                HeaderCheckBox.Size = new Size(20, 20);
                dataGridView1.Controls.Add(HeaderCheckBox);
            }
     private void HeaderCheckBox_MouseClick(object sender, MouseEventArgs e)
            {
                HeaderCheckBoxClick((CheckBox)sender);
            }
    
            private void HeaderCheckBox_KeyUp(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Space)
                    HeaderCheckBoxClick((CheckBox)sender);
            }
    
            private void HeaderCheckBoxClick(CheckBox HCheckBox)
            {
                IsHeaderCheckBoxClicked = true;
               
              
                foreach (DataGridViewRow Row in dataGridView1.Rows)
                    ((DataGridViewCheckBoxCell)Row.Cells["selected"]).Value = HCheckBox.Checked;
                if (HCheckBox.Checked)
                {
                    foreach (var item in allPatientsId)
                    {
                        listPatientId.Add(item);
                    }
                }
                else
                {
                    listPatientId = new List<string>();
                }
                dataGridView1.RefreshEdit();
                Console.WriteLine("HeaderCheckBoxClick:");
                foreach (var item in listPatientId)
                {
                    Console.WriteLine(item);
                }
                TotalCheckedCheckBoxes = HCheckBox.Checked ? TotalCheckBoxes : 0;
    
                IsHeaderCheckBoxClicked = false;
            }
    
            private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
            {
                if (e.RowIndex == -1 && e.ColumnIndex == 0)
                    ResetHeaderCheckBoxLocation(e.ColumnIndex, e.RowIndex);
            }
    
    
            private void ResetHeaderCheckBoxLocation(int ColumnIndex, int RowIndex)
            {
                //Get the column header cell bounds
                Rectangle oRectangle = this.dataGridView1.GetCellDisplayRectangle(ColumnIndex, RowIndex, true);
    
                Point oPoint = new Point();
    
                oPoint.X = oRectangle.Location.X + (oRectangle.Width - HeaderCheckBox.Width) / 2 + 1;
                oPoint.Y = oRectangle.Location.Y + (oRectangle.Height - HeaderCheckBox.Height) / 2 + 1;
    
                //Change the location of the CheckBox to make it stay on the header
                HeaderCheckBox.Location = oPoint;
            }
  • 相关阅读:
    BZOJ 4059 [Cerc2012]Non-boring sequences(启发式分治)
    牛客练习赛1 A
    2018年全国多校算法寒假训练营练习比赛(第一场)J
    2018年全国多校算法寒假训练营练习比赛(第一场)C
    2018年全国多校算法寒假训练营练习比赛(第一场)D
    2018年全国多校算法寒假训练营练习比赛(第一场)E
    Wannafly挑战赛7 E
    Wannafly挑战赛7 C
    Wannafly挑战赛7 B
    Wannafly挑战赛7 D
  • 原文地址:https://www.cnblogs.com/liuxinls/p/2980891.html
Copyright © 2011-2022 走看看