vb.net 循环遍历数据行并将每个值添加到列表框中
Private Function ColumnEqual(ByVal A As Object, ByVal B As Object) As Boolean
If A Is DBNull.Value AndAlso B Is DBNull.Value Then
Return True
End If
If A Is DBNull.Value OrElse B Is DBNull.Value Then
Return False
End If
Return A.Equals(B)
End Function
...
Public lastV As Object
...
For Each dr In wData.Rows
If lastV Is Nothing OrElse Not ColumnEqual(lastV, dr("table1")) Then
''check if first value is nothing
If lastV = Nothing Then
lastV = "00"
l = "0"
Else
dr("t1") = lastV
dr("n1") = l
End If
ListBox1.Items.Add(lastV & " <--> " & l)
lastV = dr("table1")
l = 1
ElseIf lastV Is Nothing OrElse ColumnEqual(lastV, dr("table1")) Then
l += 1
End If
Next
我使用此代码循环访问我的 DataRow
。
它将每条记录添加到 ListBox
中,但不会添加列表中的最后一条记录 DataRow
添加到列表中。
有什么帮助吗?
Private Function ColumnEqual(ByVal A As Object, ByVal B As Object) As Boolean
If A Is DBNull.Value AndAlso B Is DBNull.Value Then
Return True
End If
If A Is DBNull.Value OrElse B Is DBNull.Value Then
Return False
End If
Return A.Equals(B)
End Function
...
Public lastV As Object
...
For Each dr In wData.Rows
If lastV Is Nothing OrElse Not ColumnEqual(lastV, dr("table1")) Then
''check if first value is nothing
If lastV = Nothing Then
lastV = "00"
l = "0"
Else
dr("t1") = lastV
dr("n1") = l
End If
ListBox1.Items.Add(lastV & " <--> " & l)
lastV = dr("table1")
l = 1
ElseIf lastV Is Nothing OrElse ColumnEqual(lastV, dr("table1")) Then
l += 1
End If
Next
I use this code to loop through my DataRow
.
It adds each record into a ListBox
, but it does not add the last record in theDataRow
to the list.
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,您希望将数据行中的每一列添加为列表框中的新列表框项。
如果我是对的,那么下面的例子就可以做到。我将使用数据集:
这会将第 i 行中每列的内容添加到列表框中。
If
语句会阻止它增加i
,直到添加最后一列。请记住我还没有测试过这段代码。
华泰
If I understand you correctly, you want to add each column in the datarow as a new ListBox item in your ListBox.
If I'm right, then the following example would do it. I'd use a DataSet:
This will add the contents of each column in row i to the ListBox. The
If
statement stops it from incrementingi
until it's added the last column.Please bear in mind I haven't tested this code.
HTH