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.
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) |