Spread for ASP.NET 8.0 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.
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.
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.
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 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.
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" |
(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.)
The following steps list a different way to lock cells in the designer.