Introduction
Although I have been programming for 25 years, I just began my first Spread for Windows Forms project. When I begin a project, especially one in which I have not had any experience with the primary control I am going to use, I just do not have time to read a 3000 page assembly reference. I do appreciate such documents and reference them frequently and frantically so the objective can be reached, though. Well, I just spent a month working on my current project and decided to take a break to pass along what I have learned in what I hope is a useful form for this audience.
It is simply a collection of functions that work and complete the tasks that I have encountered to date. It is probably not the best utilization of the models, but it has proven to be very fast, regardless of that. It is also, probably not the best use of .NET technology. But I would have given my right arm to have had these. To me they are worth a thousand pages of documentation. My hope is that those of you who find it useful, and improve upon it, let me know. My e-mail address is: garypotts@ltcit.com. I would be especially interested in a knowing about the use of these functions in Spread for Web Forms. That is where I am headed next. If nothing else I hope that these function save someone else the time it took me to research and test them.
Code
In general, the Visual Basic .NET code below should be self-explanatory. The functions are named for their tasks. If the function name is AddSheets, that is what it does, add sheets to the Spread component. Simply paste the code into a new Windows Form project and pass the function the parameters it asks for. These 450+ lines of code are the heart of a complex SQL Server based professional tool application that currently has around 8,000 lines of code. Without these functions it would have probably be at around 30,000 lines of code. I hope they are of help to you, too.
Private Function AddSheets(ByRef SSControlToUse As FpSpread, ByVal NumberOfSheets As Integer, ByVal StartingNumberOfColumns As Integer, ByVal StartingNumberOfRows As Integer, ByVal ProtectionLikeExcelTF As Boolean, ByVal SheetBackColor As System.Drawing.Color, ByVal RowHeaderAutoText As FarPoint.Win.Spread.HeaderAutoText, ByVal ColumnHeaderAutoText As FarPoint.Win.Spread.HeaderAutoText) As Boolean
'Adds a Sheet for Each Question and Sets the number of Rows and Column
Dim x As Integer
Dim y As Integer
Dim z As Integer
SSControlToUse.Sheets.Count = 0
'Create the Sheets
For x = 0 To NumberOfSheets
Dim s As New FarPoint.Win.Spread.SheetView
s.ColumnCount = StartingNumberOfColumns
s.RowCount = StartingNumberOfRows
SSControlToUse.Sheets.Add(s)
Dim info As New FarPoint.Win.Spread.StyleInfo
'Set the BackColor
info.BackColor = SheetBackColor
SSControlToUse.Sheets(SSControlToUse.Sheets.Count - 1).DefaultStyle = info
'Set Protection Scheme to be like Excels for each sheet
For y = 0 To (StartingNumberOfRows - 1)
For z = 0 To (StartingNumberOfColumns - 1)
s.Cells(y, z).Locked = ProtectionLikeExcelTF
Next z
Next y
SSControlToUse.Sheets(x).RowHeaderAutoText = RowHeaderAutoText
SSControlToUse.Sheets(x).ColumnHeaderAutoText = ColumnHeaderAutoText
Next x
AddSheets = True
End Function 'AddSheets
Private Function AddSingleSheet(ByRef SSControlToUse As FpSpread, ByVal StartingNumberOfColumns As Integer, ByVal StartingNumberOfRows As Integer, ByVal ProtectionLikeExcelTF As Boolean, ByVal SheetBackColor As System.Drawing.Color, ByVal RowHeaderAutoText As FarPoint.Win.Spread.HeaderAutoText, ByVal ColumnHeaderAutoText As FarPoint.Win.Spread.HeaderAutoText) As Boolean
'Adds a Sheet for Each Question and Sets the number of Rows and Column
Dim x As Integer
Dim y As Integer
'Create the Sheets
Dim s As New FarPoint.Win.Spread.SheetView
s.ColumnCount = StartingNumberOfColumns
s.RowCount = StartingNumberOfRows
SSControlToUse.Sheets.Add(s)
Dim info As New FarPoint.Win.Spread.StyleInfo
'Set the BackColor
info.BackColor = SheetBackColor
SSControlToUse.Sheets(SSControlToUse.Sheets.Count - 1).DefaultStyle = info
'Set Protection Scheme to be like Excels for each sheet
For x = 0 To (StartingNumberOfRows - 1)
For y = 0 To (StartingNumberOfColumns - 1)
s.Cells(x, y).Locked = ProtectionLikeExcelTF
Next y
Next x
SSControlToUse.Sheets(SSControlToUse.Sheets.Count - 1).RowHeaderAutoText = RowHeaderAutoText
SSControlToUse.Sheets(SSControlToUse.Sheets.Count - 1).ColumnHeaderAutoText = ColumnHeaderAutoText
SSControlToUse.Sheets(SSControlToUse.Sheets.Count - 1).GrayAreaBackColor = Color.SlateGray
' Set operation mode and let users select multiple blocks of cells
SSControlToUse.Sheets(SSControlToUse.Sheets.Count - 1).OperationMode = FarPoint.Win.Spread.OperationMode.Normal