在我的DataGridView中,有3列,分别是“文本框”,“文本框”和“组合框”。我试图将值添加到该行的组合框。但是我找不到当前行,因为它返回一个错误并说它为空。我不知道如何处理。
Public Shared Sub ListSubvarsPA(ByVal mdl As IScrModel, ByVal dgvStd As DataGridView, ByVal dgvDiscr As DataGridView)
dgvStd.Rows.Clear()
dgvDiscr.Rows.Clear()
Dim grpName As String = My.Settings.str_elem__subvar_grpname_pa
If mdl.findElement(grpName, False) IsNot Nothing Then
Dim grpList As IScrSubVarGroup = CType(mdl.findElement(grpName, False), IScrSubVarGroup)
Dim objList As IScrNamedObjectList = grpList.getSubvarList(True)
For i As Integer = 0 To objList.count - 1
Dim obj As IScrSubVar = CType(objList.item(i), IScrSubVar)
Select Case obj.get_discr_str.Length
Case Is > 1
Dim itemindex As Integer = Array.IndexOf(obj.get_discr_str(), obj.str.src)
dgvDiscr.Rows.Add(obj.fullName.Substring(grpName.Length + 1), obj.discr_desc(itemindex).src)
Dim cbCell As New DataGridViewComboBoxCell
cbCell = CType(dgvDiscr.Rows(dgvDiscr.CurrentRow.Index).Cells(2), DataGridViewComboBoxCell)
cbCell.Items.Clear()
For iIndex = 0 To UBound(obj.get_discr_desc())
cbCell.Items.Add(obj.get_discr_desc().GetValue(iIndex))
Next
Case Else
dgvStd.Rows.Add(obj.fullName.Substring(grpName.Length + 1), obj.str.src)
End Select
Next
End If
End Sub
在这里是我要解决的问题部分,因为我找不到最新的行,因此将值添加到现有的DataGridViewCombobox值中。
Dim itemindex As Integer = Array.IndexOf(obj.get_discr_str(), obj.str.src)
dgvDiscr.Rows.Add(obj.fullName.Substring(grpName.Length + 1), obj.discr_desc(itemindex).src)
Dim cbCell As New DataGridViewComboBoxCell
cbCell = CType(**dgvDiscr.Rows(dgvDiscr.CurrentRow.Index**).Cells(2), DataGridViewComboBoxCell)
cbCell.Items.Clear()
For iIndex = 0 To UBound(obj.get_discr_desc())
cbCell.Items.Add(obj.get_discr_desc().GetValue(iIndex))
Next
问题在这里发生
Dim cbCell As New DataGridViewComboBoxCell
cbCell = CType(dgvDiscr.Rows(dgvDiscr.CurrentRow.Index).Cells(2), DataGridViewComboBoxCell)