为什么不将它添加到列表 [英] why doesn't it add to the list
问题描述
这个问题是基于这样的<一个href="http://stackoverflow.com/questions/20511009/how-to-partner-bind-items-on-different-lists/20512063?noredirect=1#comment30665730_20512063">Link
我还没有找到一个答案,但我想一个解决方案,并导致了另一个问题。
公共类markerRow
公共MarkerName作为字符串
公共CameraID作为整数
公共HostAddress作为字符串
末级
公共先生担任新markerRow
昏暗ALIST作为新的列表(中markerRow)
对于每个dtrow在markerDtable.Rows
mr.MarkerName = dtrow(MarkerName)
mr.CameraID = dtrow(CameraID)
mr.HostAddress = dtrow(HostAddress)
aList.Add(新markerRow())
下一个
这是我的想法,这code应该从数据库中添加的每一个数据到列表中的各个变量。但我仍然不知道它做什么完全相符。
我查了 aList.Count.ToString
,它给了我5个项目,这是正确的,因为我有5行我的数据库。
对于每个ELEM在ALIST
listbox.Items.Add(mr.MarkerName)
listbox.Items.Add(mr.CameraID)
下一个
要检查哪些项目在 ALIST
,我做到了..很遗憾..它只是给我的最后一个项目,5次。在MarkerName柱和摄像机ID列的最后一个项目。
我在想什么?或者有什么错我的code?
在 ALIST
应该有什么在数据库上面。不仅是最后一个项目。
公共先生担任新markerRow
昏暗ALIST作为新的列表(中markerRow)
对于每个dtrow在markerDtable.Rows
mr.MarkerName = dtrow(MarkerName)
mr.CameraID = dtrow(CameraID)
mr.HostAddress = dtrow(HostAddress)
aList.Add(新markerRow())
下一个
在这里,你创建的一个的 markerRow
的先生
和更新的是在数据表
的每一行。此外,对于每一行,你创建的另一个的 markerRow
,以及新加入 ALIST
。
对于每个ELEM在ALIST
listbox.Items.Add(mr.MarkerName)
listbox.Items.Add(mr.CameraID)
下一个
然后,对于 ALIST
每一个元素,添加的两个的项目到列表框
,并每次它的 MarkerName
和 CameraID
从先生
,而不是从 ALIST
元素中的数据。
你可能要找的东西,如:
昏暗ALIST作为新的列表(中markerRow)
对于每个dtrow在markerDtable.Rows
昏暗的MR =新markerRow()'创建的每一行新markerRow
mr.MarkerName = dtrow(MarkerName)
mr.CameraID = dtrow(CameraID)
mr.HostAddress = dtrow(HostAddress)
aList.Add(MR)的新markerRow添加到列表
下一个
对于每个ELEM在ALIST
listbox.Items.Add(elem.MarkerName)
下一个
this question is based on this Link
I haven't found an answer, but I am trying on a solution and resulted to another question..
Public Class markerRow
Public MarkerName As String
Public CameraID As Integer
Public HostAddress As String
End Class
Public mr As New markerRow
Dim aList As New List(Of markerRow)
For Each dtrow In markerDtable.Rows
mr.MarkerName = dtrow("MarkerName")
mr.CameraID = dtrow("CameraID")
mr.HostAddress = dtrow("HostAddress")
aList.Add(New markerRow())
Next
from what I think, this code should add every data from the DB to the respective variables in the list.. But I still don't know what it does exactly.
I checked the aList.Count.ToString
and it gave me 5 items, which is true since I have 5 rows in my DB..
For Each elem In aList
listbox.Items.Add(mr.MarkerName)
listbox.Items.Add(mr.CameraID)
Next
to check what items are in the aList
, I did that.. unfortunately.. it only gives me the last item, 5 times. the last item on MarkerName Column and Camera ID Column.
What am I missing? or what's wrong in my code?
the aList
should have what's on the DB above. not only the last item.
Public mr As New markerRow
Dim aList As New List(Of markerRow)
For Each dtrow In markerDtable.Rows
mr.MarkerName = dtrow("MarkerName")
mr.CameraID = dtrow("CameraID")
mr.HostAddress = dtrow("HostAddress")
aList.Add(New markerRow())
Next
Here, you are creating one markerRow
named mr
, and update it for every row in the DataTable
. Also, for every row, you create another markerRow
, and add that new one to aList
.
For Each elem In aList
listbox.Items.Add(mr.MarkerName)
listbox.Items.Add(mr.CameraID)
Next
Then, for each element in aList
, you add two items to the ListBox
, and everytime it's MarkerName
and CameraID
from mr
, and not the data from the elements of aList
.
You're probably looking for something like:
Dim aList As New List(Of markerRow)
For Each dtrow In markerDtable.Rows
Dim mr = New markerRow() ' create a new markerRow for every row '
mr.MarkerName = dtrow("MarkerName")
mr.CameraID = dtrow("CameraID")
mr.HostAddress = dtrow("HostAddress")
aList.Add(mr) ' add the new markerRow to the list '
Next
For Each elem In aList
listbox.Items.Add(elem.MarkerName)
Next
这篇关于为什么不将它添加到列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!