我无法将Checkbox
列标题添加到多选(全选)行Datagridview
,我用谷歌搜索 ,但他们让我添加checkbox
行而不是列标题。
这样我将选中所有复选框列标题单击。例如,请看下面的图片。这是我从互联网上获得的列表视图图像,但我正在使用Datagridview
.
我无法将Checkbox
列标题添加到多选(全选)行Datagridview
,我用谷歌搜索 ,但他们让我添加checkbox
行而不是列标题。
这样我将选中所有复选框列标题单击。例如,请看下面的图片。这是我从互联网上获得的列表视图图像,但我正在使用Datagridview
.
我从互联网上得到这个,但我不记得链接在哪里,最初来自 c#。
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
用法:
Sub Form1Load(sender As Object, e As EventArgs) Handles MyBase.Load
show_chkBox()
End Sub
我希望它会有所帮助