Spread ASP.NET 16
Spread for ASP.NET 16 Product Documentation / Developer's Guide / Customizing with Cell Types / Working with Graphical Cell Types / Setting a Button Cell
In This Topic
    Setting a Button Cell
    In This Topic

    A button cell displays a rectangular button (with the word Button by default unless you specify otherwise) that behaves like a button control. You can specify the text for that button or you can substitute the entire graphic image. You can also specify text to appear underlined and blue, as a hypertext link would appear. The default appearance and the three possible alternatives are shown in this figure.

    Appearances of Button Cell Types

    To create a cell that acts like a button, follow this procedure.

    For details on the properties and methods for this cell type, refer to the ButtonCellType class in the Assembly Reference.

    Using Code

    1. Define the button cell type by creating an instance of the ButtonCellType class and specify whether it is push button, image button, or link button.
    2. Specify the properties of the button by setting the properties of that instance. Specify the text in the button or an image to use.
    3. Specify the command to execute when the button is selected.
    4. Assign the type to a cell (or cells).
    5. Use the ButtonCommand event to respond to the selected button.

    Example

    In this example, create a button with text in the first cell, a button with a stored image in the cell diagonally below that, and a button with link text in the one diagonally below that. These are identical to those pictured in the figure (except for placement). Use the ButtonCommand event to respond to the selected button.

    C#
    Copy Code
    FpSpread1.ActiveSheetView.Cells[0, 0].CellType = new FarPoint.Web.Spread.ButtonCellType("OneCommand", FarPoint.Web.Spread.ButtonType.PushButton, "Click");
    FpSpread1.ActiveSheetView.Cells[1, 1].CellType = new FarPoint.Web.Spread.ButtonCellType("OneCommand", FarPoint.Web.Spread.ButtonType.ImageButton, "images/addtocart.gif");
    FpSpread1.ActiveSheetView.Cells[2, 2].CellType = new FarPoint.Web.Spread.ButtonCellType("OneCommand", FarPoint.Web.Spread.ButtonType.LinkButton, "www.componentone.com");
    
    protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
            {
                System.Drawing.Point p;
                p = (System.Drawing.Point)e.CommandArgument;
                TextBox1.Text = "You clicked the button in row " + p.X + " , column " + p.Y;
            }
    
    VB
    Copy Code
    Dim btnc1 As New FarPoint.Web.Spread.ButtonCellType()
    btnc1.CommandName = "OneCommand"
    btnc1.ButtonType = FarPoint.Web.Spread.ButtonType.PushButton
    btnc1.Text = "Click"
    FpSpread1.ActiveSheetView.Cells(0, 0).CellType = btnc1
    
    Dim btnc2 As New FarPoint.Web.Spread.ButtonCellType()
    btnc2.CommandName = "OneCommand"
    btnc2.ButtonType = FarPoint.Web.Spread.ButtonType.ImageButton
    btnc2.ImageUrl = "addtocart.gif"
    FpSpread1.ActiveSheetView.Cells(1, 1).CellType = btnc2
    
    Dim btnc3 As New FarPoint.Web.Spread.ButtonCellType()
    btnc3.CommandName = "OneCommand"
    btnc3.ButtonType = FarPoint.Web.Spread.ButtonType.LinkButton
    btnc3.Text = "www.componentone.com"
    FpSpread1.ActiveSheetView.Cells(2, 2).CellType = btnc3
    
    Private Sub FpSpread1ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.ButtonCommand
        TextBox1.Text = "You clicked the button in row " & e.CommandArgument.X & " , column " & e.CommandArgument.Y
    End Sub 
    

    Using the Spread Designer

    1. In the work area, select the cell or cells for which you want to set the cell type.
    2. Select the Home menu.
    3. Select the SetCellType icon under the CellType section.
    4. Select the cell type and any other cell properties.
    5. Select OK to close the dialog.
    6. Click Apply and Exit to close the Spread Designer.