在vb.net中,datagridview不显示单元格中的值
我用的是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 am using vb.net. I have following weird problems:
If I comment DGVCusClient.Rows.Add(), the cell in ("column1",0) does not display data. But in debug, I can see that the first cell has data assigned.
If I do not comment DGVCusClient.Rows.Add(), the cell in ("column1",0) displays its data correctly. However, it adds the row on the top for the first time. Except for the first row, it adds rows to the bottom as usual.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的代码总是可以将行添加到底部,这就是我想要的。所以我只需要首先添加新行,然后将值设置为当前单元格。
The following code can always add rows to the bottom, which is what I want. So I just need to first add new row, and then set values to current cells.