0

我有一个动态填充的datagridview。我想根据某些条件使用一些组合框填充某些列。动态添加一个comboboxcell到datagridview

但我的组合框包含在最底部的行而不是正确的行

有人可以告诉我需要做什么吗?

我要去哪里错了?

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 

回答

0

您是否将datagrid的AutoGenerateColumns属性设置为false?

dgCFG.AutoGenerateColumns = false;