Spread Windows Forms 8.0 Product Documentation
Locking a Cell

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 it is noticeable by the user.

You can lock cells using the Locked property in the Cell, Column, Row, or AlternatingRow objects. You can also set the Locked property for the StyleInfo object and apply that style to the cells you want locked. You also need to set the Protect property of the SheetView object to lock the cells. The Locked property marks the cells as 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 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) and setting the ReadOnly property. This makes the cells uneditable.

You can also specify a different color (for background or for text) or font in locked cells using the LockBackColor, LockForeColor, and LockFont properties of the SheetView or Appearance 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.

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

Using the Locked property for the Cell object (or Row or Column object for all the cells in that row or column) you can mark some cells as locked. The Protect property, for the sheet (SheetView object), must be set to true if you want the cells in that sheet 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.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";
VB
Copy Code
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

Using the Locked property for the Cells shortcut (or Rows or Columns shortcut for all the cells in that row or column) you can mark some cells as locked. The Protect property, for the Sheets shortcut, 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.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;
VB
Copy Code
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).
  2. In the properties list (in the Misc group), 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. 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.

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options | Documentation Feedback