Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Data Binding / Adding to Bound Data / Adding a Row to a Bound Sheet
In This Topic
    Adding a Row to a Bound Sheet
    In This Topic

    Once you bind a sheet to a data set you might want to add an unbound row to contain additional data. The row could then be bound using the AddRowToDataSource method.

    The following figure shows a sheet in a Spread component that contains data from a data set and an unbound row at the bottom that calculates the averages.

    Spreadsheet displaying bound data and an unbound row at the bottom

    Using Code

    1. Create your data set.
    2. Set the FpSpread object's DataSource property equal to the data set.
    3. Call the SheetView object's AddUnboundRows method to specify where to add the unbound row.
    4. Set properties for the unbound row.
    5. Set the SheetView object's AddRowToDataSource method if you want to add the row to the data source.

    Example

    This example code creates a bound FpSpread object and adds an unbound row to it.

    C#
    Copy Code
    DataSet ds = new DataSet();
    DataTable emp = new DataTable("Name");
    emp.Columns.Add("LastName");
    emp.Columns.Add("GPA (Single)", typeof(decimal));
    emp.Columns.Add("GPA (Double)", typeof(decimal));
    emp.Rows.Add(new Object[] { "Shorter", "4.12", "4.12" });
    emp.Rows.Add(new Object[] { "Williams", "2.00", "2.00" });
    emp.Rows.Add(new Object[] { "Zacheius", "3.62", "3.62" });
    ds.Tables.Add(emp);
    fpSpread1.DataSource = ds;
    fpSpread1.ActiveSheet.AddUnboundRows(3, 1);
    fpSpread1.ActiveSheet.Cells[3, 0].Text = "Average";
    fpSpread1.ActiveSheet.Cells[3, 1].Formula = "AVERAGE(B1:B3)";
    fpSpread1.ActiveSheet.Cells[3, 2].Formula = "AVERAGE(C1:C3)";
    //fpSpread1.ActiveSheet.AddRowToDataSource(3, true);
    
    VB
    Copy Code
    Dim ds = New DataSet()
    Dim emp As New DataTable("Name")
    emp.Columns.Add("LastName")
    emp.Columns.Add("GPA (Single)", GetType(Decimal))
    emp.Columns.Add("GPA (Double)", GetType(Decimal))
    emp.Rows.Add(New Object() {"Shorter", "4.12", "4.12"})
    emp.Rows.Add(New Object() {"Williams", "2.00", "2.00"})
    emp.Rows.Add(New Object() {"Zacheius", "3.62", "3.62"})
    ds.Tables.Add(emp)
    fpSpread1.DataSource = ds
    fpSpread1.ActiveSheet.AddUnboundRows(3, 1)
    fpSpread1.ActiveSheet.Cells(3, 0).Text = "Average"
    fpSpread1.ActiveSheet.Cells(3, 1).Formula = "AVERAGE(B1:B3)"
    fpSpread1.ActiveSheet.Cells(3, 2).Formula = "AVERAGE(C1:C3)"
    'fpSpread1.ActiveSheet.AddRowToDataSource(3, True)
    
    See Also