Using Protect and Cell Locking

You can protect the workbook or sheet and lock cells in the control.

Cells can still be edited if the workbook Protect property is true and the worksheet Protect property is false.

Protecting the workbook and sheet prevents cells from being edited. If you wish to allow the user to edit specific cells, protect the sheet and unlock only the cells you want the user to edit. Use the Locked property to allow or prevent editing of specific cells.

Data can be copied from locked cells.

Using Code

This example sets the Protect and Locked properties.

CS
Copy Code
gcSpreadSheet1.Sheets[0].Cells[1, 1].Locked = false;
gcSpreadSheet1.Sheets[0].Cells[1, 1].Text = "Locked";
gcSpreadSheet1.Sheets[0].Columns[3].Locked = false;
gcSpreadSheet1.Sheets[0].Rows[5].Locked = false;
gcSpreadSheet1.Protect = true;
gcSpreadSheet1.Sheets[0].Protect = true;
private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            gcSpreadSheet1.Sheets[0].Cells[1, 1].ResetLocked();
        }
VB
Copy Code
GcSpreadSheet1.Sheets(0).Cells(1, 1).Locked = False
GcSpreadSheet1.Sheets(0).Cells(1, 1).Text = "Locked"
GcSpreadSheet1.Sheets(0).Columns(3).Locked = False
GcSpreadSheet1.Sheets(0).Rows(5).Locked = False
GcSpreadSheet1.Protect = True
GcSpreadSheet1.Sheets(0).Protect = True
Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
GcSpreadSheet1.Sheets(0).Cells(1, 1).ResetLocked()
End Sub
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.