Spread for ASP.NET 11 Product Documentation
Locking a Cell
Spread for ASP.NET 11 Product Documentation > Developer's Guide > Customizing User Interaction > Customizing Interaction with Cells > Locking a Cell

You can lock a cell or range of cells and make it unavailable for editing by the end user.

You can lock cells using the Locked property in the Cell, Column, Row, AlternatingRow, or SheetView objects.

For cells marked as locked to be locked from user input, the Protect property of the sheet must be set to True, which is its default value. If it is set to False, the user can still interact with the cells.

Using the Properties Window

  1. At design time, in the Properties window, select the FpSpread component.
  2. Select the Sheets property.
  3. Click the button to display the SheetView Collection Editor.
  4. Select the Cells drop-down.
  5. Select the cells that you wish to lock.
  6. Set the Locked property.
  7. Select OK.

Using a Shortcut

Using the Locked property for the Cell, Column, or Row object, you can mark some cells as locked. The Protect property, for the sheet, must be set to true if you want the cells to be locked from user input.

Example

Making sure that the Protect property is True for the sheet, you can lock some columns of cells and then unlock some of the cells in one row.

C#
Copy Code
FpSpread1.ActiveSheetView.Protect = true;
FpSpread1.ActiveSheetView.Columns[0, 3].Locked = true;
FpSpread1.ActiveSheetView.Cells[1,1,1,2].Locked = false; 
VB
Copy Code
FpSpread1.ActiveSheetView.Protect = True
FpSpread1.ActiveSheetView.Columns[0, 3].Locked = True
FpSpread1.ActiveSheetView.Cells[1,1,1,2].Locked = False 

Using Code

Using the Locked property for the Cell, Column, or Row object, you can mark some cells as locked. The Protect property, for the sheet, must be set to True if you want the cells to be locked from user input.

Example

Making sure that the Protect property is True for the sheet, you can lock some columns of cells and then unlock some of the cells in one row.

C#
Copy Code
FpSpread1.ActiveSheetView.Protect = true;
FpSpread1.ActiveSheetView.LockBackColor = Color.LightCyan;
FpSpread1.ActiveSheetView.LockForeColor = Color.Green;

FarPoint.Web.Spread.Column columnobj;
columnobj = fpSpread1.ActiveSheetView.Columns[0, 3];
columnobj.Locked = true;
FarPoint.Web.Spread.Cell cellobj;
cellobj = fpSpread1.ActiveSheetView.Cells[1,1,1,2];
cellobj.Locked = false;

FpSpread1.ActiveSheetView.Cells[1,0,1,4].Text = "First Five"; 
VB
Copy Code
FpSpread1.ActiveSheetView.Protect = True
FpSpread1.ActiveSheetView.LockBackColor = Color.LightCyan
FpSpread1.ActiveSheetView.LockForeColor = Color.Green

Dim columnobj As FarPoint.Web.Spread.Column
columnobj = fpSpread1.ActiveSheetView.Columns(0, 3)
columnobj.Locked = True
Dim cellobj As FarPoint.Web.Spread.Cell
cellobj = fpSpread1.ActiveSheetView.Cells(1,1,1,2)
cellobj.Locked = False

FpSpread1.ActiveSheetView.Cells(1,0,1,4).Text = "First Five" 

Using the Spread Designer

  1. In the work area, select the cell or cells for which you want to lock the cells either by dragging over a range of cells or selecting row or column headers (for entire rows or columns).
  2. In the Misc section, select the Locked property and choose True.

    (Another way of doing that is to select the Cells property, click on the button to call up the Cell, Column, and Row editor, and select the cells in that editor.)

  3. Choose the sheet from the drop-down combo to the right of the designer. From the properties list (in the Misc section), set the Protect property.
  4. In the Properties window in the SheetView Collection Editor, in the Misc section, select the Protect property and set it to True if you want the cells to be locked from user input.
  5. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.

Using the Spread Designer

The following steps list a different way to lock cells in the designer.

  1. In the work area, select the cell or cells that you want to lock.
  2. Select the Home menu.
  3. Select the Lock icon from the Editing section.
  4. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.