0

I have a datagridview that gets populated dynamically. I want some of the columns to get populated with a combobox depending on some condition.

But my comboboxcell gets added at the bottom most row instead of the proper row.

Can anybody tell me what needs to be done ?

Where I'm going wrong ?

Private Sub dgvSteps_CellContentClick(ByVal sender As Object,
                                          ByVal e As DataGridViewCellEventArgs
                                          ) Handles dgvSteps.CellContentClick

        Dim reader = New XmlTextReader("C:\Qualcomm\" & tempNode.profilePath)
        reader.WhitespaceHandling = WhitespaceHandling.None
        reader.Read()
        reader.Read()
        reader.Read()
        dgv2.Rows.Clear()


        While reader.NodeType <> XmlNodeType.EndElement
            Dim str1 As String
            Dim str2 As String
            str1 = reader.Name
            str2 = reader.ReadElementString(str1)

            If reader.Name = "Port" Then
                Dim dgv2Cb As New DataGridViewComboBoxCell  'Create DatagridViewComboBoxCell
                Dim ports As String() = SerialPort.GetPortNames()
                Dim port As String
                For Each port In ports
                    dgv2Cb.Items.Add(port)
                Next port
                dgv2Cb.Sorted = True
                dgv2.Rows.Add(str1, str2)
                rowIndex = dgv2.RowCount  'Get the RowCount at the time of adding combobexcell, and add comboboxcell in that row

                dgv2.Rows(rowIndex).Cells(1) = dgv2Cb
            Else
                dgv2.Rows.Add(str1, str2)
                               End If
        End While
    End Sub
Sharat Chandra
  • 4,434
  • 7
  • 49
  • 66

1 Answers1

0

Do you set the datagrid's AutoGenerateColumns property to false?

dgCFG.AutoGenerateColumns = false;
Jim Lahman
  • 2,691
  • 2
  • 25
  • 21