Spread WPF Documentation
GetRecordCount Method
Example 


GrapeCity.Windows.SpreadSheet.Data Namespace > ConnectionBase Class : GetRecordCount Method
Gets the number of records.
Syntax
'Declaration
 
Public MustOverride Function GetRecordCount() As System.Integer
'Usage
 
Dim instance As ConnectionBase
Dim value As System.Integer
 
value = instance.GetRecordCount()
public abstract System.int GetRecordCount()

Return Value

The record count.
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