Question Cell Level Dynamic ComboBox Fill in DataGridView Cell

Sanjoy

New member
Joined
Mar 20, 2012
Messages
4
Programming Experience
3-5
Hi,

I want to add a ComboBox at Cell Level in DataGrid. i. e. There is one Static ComboBox(Suppose A) in a Cell of DataGrid, upon Selecting a value of that Combo Box, there on Next cell a ComboBox(Suppose B) will generate dynamically. My Problem is that, on first Row of Grid B ComboBox Value Changes to The value Of Current Row(When Adding a Differrent Value on 2nd Row). My Dynamic ComboBox Generation Code is Following:

VB.NET:
    Private Sub dgvValue_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvValue.CellEndEdit


        Select Case e.ColumnIndex

            Case A
                Dim dgvCboB As New DataGridViewComboBoxCell
                DT_B = FetchDatatable(dgvValue(A, e.RowIndex).EditedFormattedValue)
                dgvCboB.DataSource = DT_B
                dgvCboB.DisplayMember = "Value Name"
                dgvCboB.ValueMember = "GUID"
                dgvCboB.AutoComplete = True
                dgvValue(B, e.RowIndex) = dgvCboB
        End Select
     End Sub
 
Last edited:
That doesn't answer the question. That doesn't require you to create DataGridViewComboBoxCells on demand. You can just add two DataGridViewComboBoxColumns to your grid as you normally would. The only difference would be that you would either rebind or filter the data source of the cell in the State column when the cell in the Country column of the same row had its Value set.
 
Handle the CellValueChanged event of the grid. Test e.ColumnIndex to see if the change was in the Country column. If it was, use e.RowIndex to get the row. Get the Value from the cell in the Country column and use that to get the appropriate state data and assign that to the DataSource of the cell in the State column.
 
I don't really understand what you just posted but I assume that you're saying that it doesn't work. In that case you're doing it wrong. As we can't see what you're doing, we can't see what's wrong with it.
 
Back
Top