A colleague ran into an issue awhile back trying to edit data in a DataGrid. He had a ComboBox, and wanted to be able to edit the text to a value not bound to it.
The answer is really simple, but not well documented.
The first step is to create a class that derives from DataGridViewComboBoxCell. This is where the magic happens. By default, the DropDownStyle of the ComboBox in this column is set to ComboBoxStyle.DropDownList, which is not editable. We can change that by setting the DropDownStyle to ComboBoxStyle.DropDown.
Public Class EditableDataGridViewComboBoxCell
Inherits DataGridViewComboBoxCell
Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle)
MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
Dim box1 As ComboBox = CType(MyBase.DataGridView.EditingControl, ComboBox)
If (Not box1 Is Nothing) Then
box1.DropDownStyle = ComboBoxStyle.DropDown
End If
End Sub
End Class
The next step is to create a control that derives from DataGridViewComboBoxColumn and sets the CellTemplate property to an instance of our EditableDataGridViewComboBoxCell
Public Class EditableDataGridViewComboBoxColumn
Inherits DataGridViewComboBoxColumn
Public Sub New()
Me.CellTemplate = New EditableDataGridViewComboBoxCell
End Sub
End Class
Finally in your form, set your column to be of type EditableDataGridViewComboBoxColumn.
Once you have this implementation in place, you can do things like override the change event, and save your new value to the underlying datasource.
Have fun!