title: Adding checkbox to datagridview column header, not aligning properly
body: <p>Im trying to add a checkbox to a specific datagridview column header, I found some code online to help but it's not aligning properly and I'm not really sure how to fix it. </p>
  
  <p>Below is an image of the problem and the code, any help would be greatly appreciated!</p>
  
  <p>P.S. I think it might be something to do with properties but I've played around with them but not been successful.</p>
  
  <p><img src="https://i.stack.imgur.com/1hNdW.png" alt="enter image description here"></p>
  
  <pre><code>Private checkboxHeader231 As CheckBox
  Private Sub show_chkBox()
  Dim rect As Rectangle = DataGridView1.GetCellDisplayRectangle(columnIndexOfCheckBox, -1, True)
  ' set checkbox header to center of header cell. +1 pixel to position 
  rect.Y = 3
  rect.X = rect.Location.X + 8 + (rect.Width / 4)
  checkboxHeader231 = New CheckBox()
  With checkboxHeader231
      .BackColor = Color.Transparent
  End With
  
  checkboxHeader231.Name = "checkboxHeader1"
  checkboxHeader231.Size = New Size(18, 18)
  checkboxHeader231.Location = rect.Location
  AddHandler checkboxHeader231.CheckedChanged, AddressOf checkboxHeader231_CheckedChanged
  DataGridView1.Controls.Add(checkboxHeader231)
  End Sub
  
  Private Sub checkboxHeader231_CheckedChanged(sender As System.Object, e As System.EventArgs)
  Dim headerBox As CheckBox = DirectCast(DataGridView1.Controls.Find("checkboxHeader1", True)(0), CheckBox)
  For Each row As DataGridViewRow In DataGridView1.Rows
      row.Cells(columnIndexOfCheckBox).Value = headerBox.Checked
  Next
  End Sub
  </code></pre>