【发布时间】:2015-03-05 22:38:10
【问题描述】:
我有一个具有这种结构的书籍的数据网格视图: 网格有 3 列出版物、作者和标题。 该网格中可能有重复的记录。 数据中有 5 个出版物。
我想根据发布拆分数据,因此将值分配给 5 个变量所以我首先将所有值排序并添加到数组列表中,但我不知道如何拆分它们。
Structure abb
Public publications As String
Public author As String
Public title As String
End Structure
Public arlist As New ArrayList
Public thebooks As New abb
For i As Integer = 0 To Databook.Rows.Count - 2 'databook is the gridview
With thebooks
.publications = CStr(Databook.Rows(i).Cells(1).Value)
.author = CStr(Databook.Rows(i).Cells(2).Value)
.title = CStr(Databook.Rows(i).Cells(3).Value)
End With
If Not arlist .Contains(thebooks) Then
arlist .Add(thebooks)
End If
Next i
现在我创建了数组列表,但在该列表中有 5 个出版物,其中包含一本书或多本书。 我想有 5 个基于发布名称的数组列表(末尾有 5 个变量)。
我可能会走错第一步,因为我猜首先从 datagridview 行中还有另一种方法可以做到这一点...。
注意:VB 或 C# 的答案可以帮助我找到自己的方式。
【问题讨论】:
-
您的
ArrayList不是List(Of abb)的任何原因?这将通过消除对这些结构进行强制转换/拆箱的需要来简化拆分它的代码。 -
没有理由。我尽我所能让它发挥作用。
标签: c# arrays vb.net visual-studio arraylist