简单的方法是建立一个新的列,如@the_lotus建议的。但是如果你想这样做艰难的方式那么你需要通过继承TypedTableBase(Of T)类来创建一个自定义表。您可能需要重写/重载/映射更多的属性/方法,然后在下面的示例中显示,但是,它应该让您开始。
Public Class StorageTable
Inherits TypedTableBase(Of StorageRow)
Protected Overrides Function CreateInstance() As DataTable
Return New StorageTable()
End Function
Protected Overrides Function NewRowFromBuilder(builder As DataRowBuilder) As DataRow
Return New StorageRow(builder)
End Function
Protected Overrides Function GetRowType() As Type
Return GetType(StorageRow)
End Function
End Class
Public Class StorageRow
Inherits DataRow
Protected Friend Sub New(builder As DataRowBuilder)
MyBase.New(builder)
End Sub
Public Property Tag() As Object
End Class
简单的测试:
Using table As New StorageTable()
table.Columns.Add("Column1", GetType(String))
table.Rows.Add("value1")
Dim row As StorageRow = DirectCast(table.Rows(0), StorageRow)
row.Tag = "value2"
Debug.WriteLine("Column1={0}, Tag={1}", row.Item(0), row.Tag)
End Using
输出:
列1 =值,标签=数值
你可以添加一个新列,并将其存储在那里。 – 2014-11-05 18:05:58