I use this code to locate a checkbox in Header of Datagridview.
(我使用此代码在Datagridview标头中找到一个复选框。)
But with changing scrolbar of datagridview, locate of checkbox changed. (但是随着datagridview滚动栏的更改,复选框的位置也发生了变化。)
// customize dataviewgrid, add checkbox column
DataGridViewCheckBoxColumn checkboxColumn = new DataGridViewCheckBoxColumn();
checkboxColumn.Width = 30;
checkboxColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridView1.Columns.Insert(0, checkboxColumn);
// add checkbox header
Rectangle rect = dataGridView1.GetCellDisplayRectangle(0, -1, true);
// set checkbox header to center of header cell. +1 pixel to position correctly.
rect.X = rect.Location.X + 8;
rect.Y = rect.Location.Y + 10;
rect.Width = rect.Size.Width;
rect.Height = rect.Size.Height;
CheckBox checkboxHeader = new CheckBox();
checkboxHeader.Name = "checkboxHeader";
checkboxHeader.Size = new Size(15, 15);
checkboxHeader.Location = rect.Location;
checkboxHeader.CheckedChanged += new EventHandler(checkboxHeader_CheckedChanged);
dataGridView1.Controls.Add(checkboxHeader);
Like this pictures :
(像这样的图片:)
ask by user3812553 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…