Hi there member 8599340,
To fix this, you need to create two classes which together will make it possible to use your custom Combobox in a DataGridView. The first class should derive the
DataGridViewComboBoxCell class, and the other should derive the
DataGridViewComboBoxColumn class.
Suppose your custom ComboBox is implemented in a class named MyCBO, these two classes might look like this:
Public Class MyDataGridViewComboBoxCell
Inherits DataGridViewComboBoxCell
Public Sub New()
MyBase.New()
End Sub
Public Overrides ReadOnly Property EditType() As Type
Get
Return GetType(MyCBO)
End Get
End Property
Public Overrides Sub InitializeEditingControl(_
ByVal rowIndex As Integer, _
ByVal formattedValue As Object, _
ByVal cellStyle As DataGridViewCellStyle)
MyBase.InitializeEditingControl(rowIndex, formattedValue, cellStyle)
Dim ctl As MyCBO = CType(DataGridView.EditingControl, MyCBO)
If ctl IsNot Nothing Then
FillColorList(ctl)
ctl.SelectedValue = formattedValue
End If
End Sub
End Class
Public Class MyDataGridViewComboBoxColumn
Inherits DataGridViewComboBoxColumn
Public Sub New()
MyBase.New()
MyBase.CellTemplate = New MyDataGridViewComboBoxCell()
End Sub
End Class
And that's really all there is to it!