To view a printable version of this article in a PDF viewer, click here for PDF.
Introduction
In Spread for Web Forms, the command buttons and the sheet name tabs appear in a customizable tool bar at the edge of the control. This tool bar is called the command bar. The ability to customize both the appearance of the command bar and the selection of buttons, even creating your own buttons, is one of the features of Spread for Web Forms. In this brief introduction, we will give you a sample of the types of customization you can do with the command bar to tailor it to your application.
The Command Bar
The command bar is displayed at the bottom of the control when the Visible property of the FpSpread control class is set to true. The command bar can include the sheet name tabs (TabInfo), the command buttons (CommandBarInfo), and the page navigation aids (PagerInfo) as show in this figure.

Parts of a Typical Command Bar
The page navigation buttons can be repositioned in the command bar or not displayed at all. Refer to the product documentation for details on all the options available. In this brief note, we discuss the command buttons in particular.
Customizing the Command Buttons
There are several ways to customize the buttons in the command bar. Here is a picture of a typical command bar, with each command button labeled.
Command Buttons
In order to customize the appearance of the command buttons, there are two things you can do. First, you can set the properties in the CommandBarInfo class to customize the colors, fonts, and button types (push button, by default, or hyperlink, or customized images). Second, you can catch the CreateButton event of the FpSpread control and set any of various properties. When the CreateButton event fires, the Command property contains the name of the button being created. Then you can perform the following customizations for the buttons:
- either enable or disable the button (with the Enabled property)
- set the appropriate image properties to display for the image buttons (with the EnabledImgURL and DisabledImgURL properties)
- define the text on the button for link and push buttons (with the Label property)
In Spread for Web Forms, a Visible property can be used to hide an individual button. Also you are able to place the command bar at the top or bottom of the control. Another way to customize the command bar is to add a new button to perform a specific action on the page. To do this, use any event that happens immediately before the Page renders to the client. One way is to override the Page's Render method. Then use the FindControl method to help you get the rendered table in the HTML page that includes the command bar and add cells to this table. Here is some sample Visual Basic code that adds a button to the command bar with the label "New Button". It submits the page back with event information that is caught at the server.
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim updateBtn As Control = FpSpread1.FindControl("Update")
Dim tc As TableCell
Dim tr As TableRow
Dim tc1 As New TableCell()
Dim btn As New Button()
If Not updateBtn Is Nothing Then
tc = updateBtn.Parent
tr = tc.Parent
tr.Cells.Add(tc1)
btn.CausesValidation = False
btn.Text = "My Button"
btn.Attributes.Add("onclick", "javascript:" + Me.Page.GetPostBackEventReference(FpSpread1, "my command") + "; return false;")
tc1.Controls.Add(btn)
End If
MyBase.Render(writer)
End Sub
Private Sub FpSpread1_ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.ButtonCommand
If e.CommandName = "my command" Then
FpSpread1.ActiveSheetView.Cells(FpSpread1.ActiveSheetView.ActiveRow, FpSpread1.ActiveSheetView.ActiveColumn).BackColor = Color.Red
End SubThis causes the ButtonCommand event to fire for the FpSpread control. The code that we can use in response to this button is as follows:
Conclusion
The command bar in Spread for Web Forms is highly customizable with options for changing the appearance, the location, and even the addition of buttons. With all this functionality, you can create high performance applications without too much effort.
This is just a brief introduction to the customizations that are possible with the Command Bar in Spread for Web Forms. For more information, read the chapter in the Developer’s Guide and keep an eye on the online forum where questions are answered about a range of customer issues.
To view a printable version of this article in a PDF viewer, click here for PDF.
© 2004 FarPoint Technologies, Inc. All rights reserved. Spread, Spread for Web Forms, and Spread for Windows Forms are trademarks of FarPoint Technologies, Inc. Other brand and product names are trademarks or registered trademarks of their respective holders.