Spread Silverlight Documentation
AddExternalConnectionType Method
Example 


GrapeCity.Windows.SpreadSheet.Data Namespace > ConnectionBase Class : AddExternalConnectionType Method
The type of the external connection.
Gets the type of the external connection.
Syntax
'Declaration
 
Public Shared Sub AddExternalConnectionType( _
   ByVal type As System.Type _
) 
'Usage
 
Dim type As System.Type
 
ConnectionBase.AddExternalConnectionType(type)
public static void AddExternalConnectionType( 
   System.Type type
)

Parameters

type
The type of the external connection.
Example
This example binds to a data source.
public class CustomConnection : GrapeCity.Windows.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 button1_Click(object sender, RoutedEventArgs e)
        {
            // This line of code adds the custom connection type for binding engine.
            GrapeCity.Windows.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" }, 
    };
            gcSpreadSheet1.Invalidate();
        }
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
See Also

Reference

ConnectionBase Class
ConnectionBase Members