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.
Another way to lock cells is to make them text cells (using the TextCellType) and set the ReadOnly property. This makes the cells uneditable.
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.
Return to the overview of Customizing Interaction with Cells.
Using the Properties Window
- At design time, in the Properties window, select the FpSpread component.
- Select the Sheets property.
- Click the button to display the SheetView Collection Editor.
- Select the Cells drop-down.
- Select the cells that you wish to lock.
- Set the Locked property.
- 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
- 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).
- 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.)
- 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.
- 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.
- 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.
- In the work area, select the cell or cells that you want to lock.
- Select the Home menu.
- Select the Lock icon from the Editing section.
- From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.