Public Class CustomConnection
Inherits GrapeCity.Windows.SpreadSheet.Data.ConnectionBase
Private fields As String() = {"Name", "Age", "Title"}
Public Overrides ReadOnly Property DataFields() As String()
Get
Return Me.fields
End Get
End Property
Public Overrides Function CanOpen() As Boolean
Return TypeOf Me.DataSource Is Array
End Function
Public Overrides Function GetRecordCount() As Integer
Return TryCast(Me.DataSource, Array).GetLength(0)
End Function
Protected Overrides Function GetRecord(recordIndex As Integer) As Object
Return recordIndex
End Function
Protected Overrides Function GetRecordValue(record As Object, field As String) As Object
Return TryCast(Me.DataSource, Array).GetValue(CInt(record), Array.IndexOf(fields, field))
End Function
End Class
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
' This line of code adds the custom connection type for binding engine.
GrapeCity.Windows.SpreadSheet.Data.ConnectionBase.AddExternalConnectionType(GetType(CustomConnection))
Me.gcSpreadSheet1.ActiveSheet.DataSource = New Object(,) {{"Sarah", 34, "Tester"}, {"Neil", 28, "Dev"}, {"Tom", 41, "Manager"}, {"John", 22, "Dev"}, {"Perter", 20, "Tester"}}
gcSpreadSheet1.Invalidate()
End Sub