Class tbCell
Inherits DataGridViewTextBoxCell
Private WithEvents btn As Button
Public Event ButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, _
ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle)
MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
btn = New Button
btn.Text = "Z"
btn.Font = DataGridView.EditingControl.Font
Dim rct As Rectangle = DataGridView.GetCellDisplayRectangle(Me.ColumnIndex, Me.RowIndex, True)
Dim pt As Point = rct.Location
pt.X += rct.Width - btn.Width
btn.Size = New Size(20, rct.Height)
btn.Location = pt
DataGridView.Controls.Add(btn)
btn.BringToFront()
End Sub
Public Overrides Sub DetachEditingControl()
MyBase.DetachEditingControl()
DataGridView.Controls.Remove(btn)
btn = Nothing
End Sub
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn.Click
MsgBox("clicked button")
RaiseEvent ButtonClick(DataGridView, e)
End Sub
End Class