Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with combo box in datagrid

Status
Not open for further replies.

tbailey

Technical User
Jul 13, 2002
3
0
0
US
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:
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
I’m new to vb.net so any assistance would be greatly appreciated.
 
On combo box selectedIndexChanged, save the value in the datagrid cell.
 
3DDD,

Thanks for the suggestion. The SelectedIndexChanged didn't fix it. It's working correctly when your editing an exsisting row of data. It's just not able to append a new row, unless you type the value directly into the datagrid cell.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top