2
我試圖添加一個複選框到特定的datagridview列標題,我發現一些代碼聯機幫助,但它沒有正確對齊,我真的不知道如何解決它。添加複選框到datagridview列標題,沒有正確對齊
下面是問題和代碼的形象,任何幫助將不勝感激!
P.S.我認爲這可能是與物業有關,但我已經與他們玩過,但沒有成功。
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
這是什麼評論「」設置複選框頭頭單元格的中心+1像素定位@ – DevelopmentIsMyPassion 2013-03-20 21:52:24
我忘了取消刪除的代碼段,這是有前我上傳了一秒,我將它整理出來! – 2013-03-20 22:18:38