Spread WPF 14
Spread WPF Documentation / Developer's Guide / Managing Data / Binding to Data
In This Topic
    Binding to Data
    In This Topic

    GcSpreadSheet supports binding to any object that implements the IEnumerable interface. This includes the Ilist, ObservableCollection, and WCF data source. Binding to data sets or data tables and the IBindingList data source is also supported.

    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.

    Using Code

    The following example binds the sheet with the DataSource property.

    CS
    Copy Code
    System.Data.DataTable dt = new System.Data.DataTable("Test");
    System.Data.DataRow dr = default(System.Data.DataRow);
    dt.Columns.Add("Series0");
    dt.Columns.Add("Series1");
    dr = dt.NewRow();
    dr[0] = 2;
    dr[1] = 1;
    dt.Rows.Add(dr);   
    dr = dt.NewRow();
    dr[0] = 4;
    dr[1] = 2;
    dt.Rows.Add(dr);   
    dr = dt.NewRow();
    dr[0] = 3;
    dr[1] = 4;
    gcSpreadSheet1.Sheets[0].AutoGenerateColumns = true;
    gcSpreadSheet1.Sheets[0].DataSource = dt;
    gcSpreadSheet1.Invalidate();
    private void button1_Click(object sender, RoutedEventArgs e)
      {
            gcSpreadSheet1.Sheets[0].ReloadBindingData();
            gcSpreadSheet1.Invalidate();
      }
    
    VB.NET
    Copy Code
    Dim dt As New System.Data.DataTable("Test")
    Dim dr As System.Data.DataRow
    dt.Columns.Add("Series0")
    dt.Columns.Add("Series1")
    dr = dt.NewRow()
    dr(0) = 2
    dr(1) = 1
    dt.Rows.Add(dr)
    dr = dt.NewRow()
    dr(0) = 4
    dr(1) = 2
    dt.Rows.Add(dr)
    dr = dt.NewRow()
    dr(0) = 3
    dr(1) = 4
    dt.Rows.Add(dr)
    GcSpreadSheet1.Sheets(0).AutoGenerateColumns = True
    GcSpreadSheet1.Sheets(0).DataSource = dt
    GcSpreadSheet1.Invalidate()
    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
            GcSpreadSheet1.Sheets(0).ReloadBindingData()
            GcSpreadSheet1.Invalidate()
        End Sub
    
    See Also