簡單的方法是建立一個新的列,如@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