# Locking a Cell

Learn how to lock cells and make them uneditable in Spread.NET with simple code examples.

## Content

You can lock a cell or range of cells and make it unavailable for editing by the end user. You can make the appearance of locked cells different so that the locked cells are noticeable by the user.
You can lock cells using the [Locked](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.Locked.html) property in the [Cell](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.html), [Column](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.html), [Row](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Row.html), or [AlternatingRow](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.AlternatingRow.html) objects. You can also set the Locked property for the [StyleInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.StyleInfo.html) object and apply that style to the cells you want locked. You also need to set the [Protect](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.Protect.html) property of the [SheetView](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.html) object to lock the cells. The **Locked** property marks the cells to be locked, and the **Protect** property sets whether to lock those cells. For cells marked as locked to be locked from user input, the [Protect](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.Protect.html) 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.
Another way to lock cells is to make them text cells (using the [TextCellType](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.CellType.TextCellType.html)) and set the **ReadOnly** property. This makes the cells non-editable.
You can also specify a different color (for background or for text) or font in locked cells using the [LockBackColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.LockBackColor.html), [LockForeColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.LockForeColor.html), and [LockFont](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.LockFont.html) properties of the [SheetView](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.html), [Appearance](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Appearance.html), [Cell](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.html), [Column](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.html), [Row](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Row.html), [NamedStyle](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.NamedStyle.html), or [StyleInfo](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.StyleInfo.html) objects.
Locking a cell does not lock any shapes (floating objects) over that cell. A protected sheet only means that all the cells in that sheet marked as locked are locked; it does not apply to shapes over that sheet. For locking shapes, refer to [Customizing Drawing](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactshapes).

## Using the Properties Window

1. At design time, in the **Properties** window, select the Spread component.
2. Select the **Sheets** property.
3. Click the button to display the **SheetView Collection Editor**.
4. In the **Properties** window on the right side of the **SheetView Collection Editor**, select the **Cells** property for the sheet.
5. Click the button to display the **Cell, Column, and Row Editor**.
6. In the editor, select the cells to mark as locked.
7. Select the **Locked** property and set the value to **True**.
8. If you want to apply this change, click **Apply**.
9. Click **OK** to close the **Cell, Column, and Row** editor.
10. In the **Properties** window on the right side of the **SheetView Collection Editor**, in the **Behavior** group, select the **Protect** property and set it to **True** if you want the cells to be locked from user input.
11. Click **OK** to close the **SheetView Collection Editor**.

## Using Code

1. Set the [Locked](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.Locked.html) property for the [Cell](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.html) object (or [Row](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Row.html) or [Column](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.html) object for all the cells in that row or column) to mark some cells as locked.
2. Set the [Protect](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.Protect.html) property for the sheet ([SheetView](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.html) object) to True if you want the cells that are marked as locked in that sheet to be locked from user input.

**Example**
Making sure that the [Protect](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.Protect.html) property is true for the sheet, you can lock specified columns of cells and then unlock some of the cells in one row, as shown in the following example.

```csharp
fpSpread1.ActiveSheet.Protect = true;
fpSpread1.ActiveSheet.LockBackColor = Color.LightCyan;
fpSpread1.ActiveSheet.LockForeColor = Color.Green;
FarPoint.Win.Spread.Column columnobj;
columnobj = fpSpread1.ActiveSheet.Columns[0, 3];
columnobj.Locked = true;
FarPoint.Win.Spread.Cell cellobj;
cellobj = fpSpread1.ActiveSheet.Cells[1,1,1,2];
cellobj.Locked = false;
fpSpread1.ActiveSheet.Cells[1,0,1,4].Text = "First Five";
```

```vbnet
fpSpread1.ActiveSheet.Protect = True
fpSpread1.ActiveSheet.LockBackColor = Color.LightCyan
fpSpread1.ActiveSheet.LockForeColor = Color.Green
Dim columnobj As FarPoint.Win.Spread.Column
columnobj = fpSpread1.ActiveSheet.Columns(0, 3)
columnobj.Locked = True
Dim cellobj As FarPoint.Win.Spread.Cell
cellobj = fpSpread1.ActiveSheet.Cells(1,1,1,2)
cellobj.Locked = False
fpSpread1.ActiveSheet.Cells(1,0,1,4).Text = "First Five"
```

## Using a Shortcut

1. Set the [Locked](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.Locked.html) property for the **Cells** shortcut (or **Rows** or **Columns** shortcut for all the cells in that row or column) to mark some cells as locked.
2. Set the [Protect](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.Protect.html) property for the **Sheets** shortcut to True if you want the cells that are marked as locked in that sheet to be locked from user input.

**Example**
Making sure that the **Protect** property is True for the sheet, you can lock specific columns of cells and then unlock some of the cells in one row, as shown in the following example.

```csharp
fpSpread1.ActiveSheet.Protect = true;
fpSpread1.ActiveSheet.LockBackColor = Color.LightCyan;
fpSpread1.ActiveSheet.LockForeColor = Color.Green;
fpSpread1.ActiveSheet.Columns[0, 3].Locked = true;
fpSpread1.ActiveSheet.Cells[1,1,1,2].Locked = false;
```

```vbnet
fpSpread1.ActiveSheet.Protect = True
fpSpread1.ActiveSheet.LockBackColor = Color.LightCyan
fpSpread1.ActiveSheet.LockForeColor = Color.Green
fpSpread1.ActiveSheet.Columns(0, 3).Locked = True
fpSpread1.ActiveSheet.Cells(1,1,1,2).Locked = False
```

## 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).
    (Another way of doing this 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.)
2. In the properties list (in the **Misc** group), select the **Locked** property and choose **True**.
3. Click the sheet name tab for the sheet that contains the cells. From the properties list (in the **Behavior** category), select the **Protect** property button to display the **SheetView Collection Editor**.
4. In the **Properties** window in the **SheetView Collection Editor**, in the **Behavior** group, 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.

## See Also

[Understanding Edit Mode in a Cell](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cell-focus/spwin-celleditmode)