【发布时间】:2011-09-20 20:21:32
【问题描述】:
我正在使用 vb.net。我有以下奇怪的问题: 如果我注释 DGVCusClient.Rows.Add(),则 ("column1",0) 中的单元格不显示数据。但是在调试中,我可以看到第一个单元格分配了数据。 如果我不评论 DGVCusClient.Rows.Add(),则 ("column1",0) 中的单元格会正确显示其数据。但是,它第一次在顶部添加了行。除了第一行,它像往常一样在底部添加行。
Dim i As Integer = DGVCusClient.CurrentRow.Index
If Not ContainRecord(tempCusid, tempCltid) Then
Dim i As Integer = DGVCusClient.CurrentRow.Index
DGVCusClient.Item("Column1", i).Value = "a"
DGVCusClient.Item("Column2", i).Value = "b"
'DGVCusClient.Rows.Add()
End If
Private Function ContainRecord(ByVal strCusid As String, ByVal strCltid As String) As Boolean
For i As Integer = 0 To DGVCusClient.Rows.Count - 1
If Not DGVCusClient.Item("Column1", i).Value Is Nothing AndAlso Not DGVCusClient.Item("Column2", i).Value Is Nothing Then
If DGVCusClient.Item("Column1", i).Value.ToString = strCusid AndAlso DGVCusClient.Item("Column2", i).Value.ToString = strCltid Then
Return True
End If
End If
Next
Return False
End Function
【问题讨论】:
-
为什么有重复的“i”变量?
标签: vb.net datagridview