There are couple of posts on DataGridViewComboBox
but they don't cover this specific case.
I have a DGV in a shoe billing form, and the first three columns are comboboxes. The first, for Model; second, for Color; third, for Number.
Since I want people to only sell what's in stock, in CellValueChanged
; depending on the ColumnIndex
I clear the next combo and insert the corresponding Items. Quick example, I have "Nike Pegassus" in the first combo, I select "Green" on the second one, and I select all the available numbers for that model and color and insert those into third column, after I cleared items in there, in case there was another color selected. Here's part of the code
If e.RowIndex >= 0 Then
If e.ColumnIndex = 0 Then
Dim objColumna As DataGridViewComboBoxColumn = dtgDetalle.Columns(1)
Dim colItems As New Collection
Dim Dattabla As DataTable
Dim objColor As New clsColor(objObjeto.Sesion)
Dattabla = objColor.BuscarTodos("CodColor IN (select distinct Stock.CodColor from Stock inner join Color on Stock.CodColor = Color.CodColor where Stock.Cantidad > 0 AND Stock.CodModelo=" & CType(objColumna.Items(dtgDetalle.Rows(e.RowIndex).Cells(0).Value), clsElementoListaFactura).Codigo & ")")
objColor = Nothing
objColumna = dtgDetalle.Columns(1)
objColumna.Items.Clear()
dtgDetalle.Rows(e.RowIndex).Cells(1).Value = Nothing
dtgDetalle.Rows(e.RowIndex).Cells(2).Value = Nothing
For Each darRecord In Dattabla.Rows
objColor = New clsColor(objObjeto.Sesion)
objColor.Codigo = darRecord.item("CodColor").ToString
Dim objElemento As New clsElementoListaFactura(darRecord.item("Color").ToString, objColumna.Items.Count, "C", CInt(darRecord.item("CodColor").ToString), "1")
objColumna.Items.Add(objElemento)
objColor = Nothing
Next
objColumna.ValueMember = "ItemData"
objColumna.DisplayMember = "Name"
. . . . . .
That works just fine for only one row! When I go to row #2 and change the index of the first combo, I want only to Combos (1, 1) and (1, 2) to be altered, but I get also (0, 1) and (0, 2) cleared and with the new values inserted. What would be the best way for me to clear the items of a specific row within a column, and then insert items only in that cell? If I'm not being clear, please ask. This is really starting to become a pain. Thanks!