I have a datagrid with 1 column (Case Type). I’m adding a combo box to the datagrid which is pulling data from another table. The problem I’m having is that the datagrid will not save a new row of data, when the combo box is used to select a value. If you type a value in the cell, it works fine. Also, when you use the combo box to edit an existing record, that also works fine.
The code I’m using to create the combo box and to save the selection is pretty standard:
I’m new to vb.net so any assistance would be greatly appreciated.
The code I’m using to create the combo box and to save the selection is pretty standard:
Code:
Private Sub CreateDropDownTypeDesc(ByVal sender As Object, ByVal e As System.EventArgs)
With colTypeDescComboBox
.DataSource = dvCaseTypes
.DisplayMember = "Description"
.ValueMember = "Code"
.Width = ColType.Width
'set cursor style to arrow instead of IBeam
.Cursor = Cursors.Arrow
End With
Me.colType.TextBox.Controls.Add(colTypeDescComboBox)
Try
'Preselect correct value in drop down
Me.colTypeDescComboBox.Text = dgType.Item(dgType.CurrentRowIndex, 0)
Catch eNull As InvalidCastException
End Try
End Sub
Private Sub SaveChangesDropDownTypeDesc(ByVal sender As Object, ByVal e As System.EventArgs)
'set type field with selected text
Me.dgType.Item(dgCaseType.CurrentRowIndex, 0) = Me.colTypeDescComboBox.Text
End Sub