Hey I did it! Thanks Matt!
'Sorry guys I still love Visual Basic... assuming LV here is a List View control
Private Sub LV_DrawColumnHeader(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs) Handles LV.DrawColumnHeader
If e.ColumnIndex = 0 Then
Dim cck As New CheckBox With {.Text = "", .Visible = True}
LV.SuspendLayout() : e.DrawBackground()
cck.BackColor = Color.Transparent
cck.UseVisualStyleBackColor = True
cck.BackgroundImage = My.Resources.CheckboxBackground
cck.SetBounds(e.Bounds.X, e.Bounds.Y, _
cck.GetPreferredSize(New Size(e.Bounds.Width, e.Bounds.Height)).Width, _
cck.GetPreferredSize(New Size(e.Bounds.Width, e.Bounds.Height)).Width)
cck.Size = New Size(cck.GetPreferredSize(New Size(e.Bounds.Width - 1, e.Bounds.Height)).Width + 1, e.Bounds.Height)
cck.Location = New Point(3, 0)
LV.Controls.Add(cck)
cck.Show()
cck.BringToFront()
e.DrawText(TextFormatFlags.VerticalCenter Or TextFormatFlags.Left)
LV.ResumeLayout(True)
Else
e.DrawDefault = True
End If
End Sub
Private Sub LV_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewItemEventArgs) Handles LV.DrawItem
e.DrawDefault = True
End Sub
Private Sub LV_DrawSubItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewSubItemEventArgs) Handles LV.DrawSubItem
e.DrawDefault = True
End Sub
In my code above, I just want to draw a checkbox at first column header... That is, e.ColumnIndex = 0.
In order to make the checkbox respond properly to user's click, we need to add handler with this piece of code.
'this line should be added before LV.ResumeLayout()
AddHandler cck.CheckedChanged, AddressOf theCheckboxInHeader_CheckChanged
'then add this procedure elsewhere in the file.
Private Sub theCheckboxInHeader_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Enter code here
End Sub
Due to stackoverflow.com policy, new users (such as me) are forbidden to post images... so I cannot post my screenshot here. http://i.imgur.com/tfiFl.png
Btw... does stackoverflow.com code highlighting javascript only supports C#?