Spread WPF Documentation
GrapeCity.Windows.SpreadSheet.Data Namespace / Worksheet Class / DataSource Property
Example


In This Topic
    DataSource Property (Worksheet)
    In This Topic
    Gets or sets the data source that populates the sheet.
    Syntax
    'Declaration
     
    <DefaultValueAttribute("")>
    Public Property DataSource As Object
    'Usage
     
    Dim instance As Worksheet
    Dim value As Object
     
    instance.DataSource = value
     
    value = instance.DataSource
    [DefaultValue("")]
    public object DataSource {get; set;}

    Property Value

    The data source that populates the sheet.
    Example
    This example sets the DataSource property.
    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();
      }
    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