user2194838 user2194838 - 1 month ago 7
Vb.net Question

add items to an already existing combobox cell in a datagridview comboBox column

How can I add items to an already existing combobox cell in a datagridview combobox column. ProductGrid is dataGridView.

With ProductGrid
Dim objSerialNumber As New DataGridViewTextBoxColumn
With objSerialNumber
.Name = "SerialNumber"
.HeaderText = "SerialNumber"
.Visible = False
.Width = lGridWidth * 1.2
End With
.Columns.Add(objSerialNumber)
End With


There is another function where i have to add items in SerialNumber comboBox. And item that i have to add is in array. And which line of code will be used to remove items from comboBox if already added in ComboBox column.

Answer

I solved the problem stated above in this manner. gSerialNumberArray contains items that i have to add.

 Dim cbCell As New DataGridViewComboBoxCell

    For k = 0 To ProductGrid.Rows.Count - 1
        cbCell = ProductGrid.Rows(k).Cells("SerialNumber")
        For iIndex = 0 To UBound(gSerialNumberArray)
            cbCell.Items.Add(gSerialNumberArray(iIndex))  
        Next
    Next
Comments