Binding to Data
Spread WinRT Documentation > Developer's Guide > Managing Data > Binding to Data

GcSpreadSheet supports binding to any object that implements the IEnumerable interface. This includes the Ilist, ObservableCollection, and WCF data source.

GcSpreadSheet supports one way data binding. Changes to the source automatically update the target but, changes to the target are not propagated back to the source.

Specific columns can be bound with the DataField property. You can set the data source with the DataSource property.

Using Code

This example binds data.

CS
Copy Code
class item
        {
            public int Series1 { get; set; }
            public int Series2 { get; set; }
            public item(int series1, int series2) { Series1 = series1; Series2 = series2; }
        }
        item[] table = new item[3] { new item(2, 1), new item(4, 2), new item(3, 4) };
        public MainPage()
        {
            this.InitializeComponent();
            gcSpreadSheet1.Sheets[0].AutoGenerateColumns = true;
            gcSpreadSheet1.Sheets[0].DataSource = table;
        }
VB
Copy Code
Class item
        Public Property Series1() As Integer
            Get
                Return m_Series1
            End Get
            Set(value As Integer)
                m_Series1 = Value
            End Set
        End Property
        Private m_Series1 As Integer
        Public Property Series2() As Integer
            Get
                Return m_Series2
            End Get
            Set(value As Integer)
                m_Series2 = Value
            End Set
        End Property
        Private m_Series2 As Integer
        Public Sub New(series1__1 As Integer, series2__2 As Integer)
            Series1 = series1__1
            Series2 = series2__2
        End Sub
    End Class
    Private table As item() = New item(2) {New item(2, 1), New item(4, 2), New item(3, 4)}
    Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
        gcSpreadSheet1.Sheets(0).AutoGenerateColumns = True
        gcSpreadSheet1.Sheets(0).DataSource = table
    End Sub
See Also