GrapeCity.Xaml.SpreadSheet.Data Namespace > ConnectionBase Class : AddExternalConnectionType Method |
'Usage Dim type As Type ConnectionBase.AddExternalConnectionType(type)
public class CustomConnection : GrapeCity.Xaml.SpreadSheet.Data.ConnectionBase { private string[] fields = { "Name", "Age", "Title" }; public override string[] DataFields { get { return this.fields; } } public override bool CanOpen() { return this.DataSource is Array; } public override int GetRecordCount() { return (this.DataSource as Array).GetLength(0); } protected override object GetRecord(int recordIndex) { return recordIndex; } protected override object GetRecordValue(object record, string field) { return (this.DataSource as Array).GetValue((int)record, Array.IndexOf(fields, field)); } } private void Button_Click_1(object sender, RoutedEventArgs e) { // This line of code adds the custom connection type for binding engine. GrapeCity.Xaml.SpreadSheet.Data.ConnectionBase.AddExternalConnectionType(typeof(CustomConnection)); this.gcSpreadSheet1.ActiveSheet.DataSource = new object[,] { { "Sarah", 34, "Tester" }, { "Neil", 28, "Dev" }, { "Tom", 41, "Manager" }, { "John", 22, "Dev" }, { "Perter", 20, "Tester" }, }; }
Public Class CustomConnection Inherits GrapeCity.Xaml.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 Button_Click_1(sender As Object, e As RoutedEventArgs) ' This line of code adds the custom connection type for binding engine. GrapeCity.Xaml.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"}} End Sub
Target Platforms: Windows Server 2012, Windows RT