Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,
I have a unbound DataGridView with two columns. First column is just string values.
Second column I want to display a combobox, only when user click the cell(not the whole column as DataGridViewColumn). I use the below code which is incorrect and gives me the error : Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
The first column is popuated, and the second column is empty.

The code is as below :
 Private Sub DGVFieldsMap_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVFieldsMap.CellEnter
        If e.ColumnIndex = 1 Then
            If cboClmCell Is Nothing Then
                Dim dgv As DataGridView = CType(sender, DataGridView)
                cboClmCell = New DataGridViewComboBoxCell
                cboClmCell.Items.Add("A")
                cboClmCell.Items.Add("B")
                cboClmCell.Items.Add("C")
                cboClmCell.Items.Add("D")
                cboClmCell.Items.Add("E")
                cboClmCell.Items.Add("F")
                dgv.Focus()
                dgv(e.ColumnIndex, e.RowIndex) = cboClmCell '[Error Here]
                isCombo = True
            End If
        End If
    End Sub

Private Sub DGVFieldsMap_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DGVFieldsMap.CellValidating
        If e.ColumnIndex = 1 Then
            Dim dgv As DataGridView = CType(sender, DataGridView)
            If isCombo Then
                isCombo = False
                cboClmCell = Nothing
                dgv(e.ColumnIndex, e.RowIndex) = New DataGridViewTextBoxCell()
            End If
        End If
End Sub


Can anybody give me a complete working example with two columns, the second column being a ComboBoxCell, but only when user clicks. Also I need to get the selected values in the DataGridView cell. Thanks In Advance.
Posted
Updated 12-Aug-12 1:25am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900