Posted 7 September 2023, 6:39 pm EST
Hi Vijay,
This works, but the gridlines separating columns disappears, which is annoying. How do I get them back?
You can set the border of the locked cell headers as shown in the following updated code-snippet:
foreach (FarPoint.Win.Spread.Column column in fpSpread1.ActiveSheet.ColumnHeader.Columns)
{
FarPoint.Win.Spread.Cell cell = fpSpread1.ActiveSheet.ColumnHeader.Cells[0, column.Index];
cell.Locked = true;
cell.Renderer = new GeneralCellType();
cell.LockForeColor = Color.Black;
cell.Border = new ComplexBorder(new ComplexBorderSide(ComplexBorderSideStyle.ThinLine, Color.LightGray));
}
foreach (FarPoint.Win.Spread.Row row in fpSpread1.ActiveSheet.RowHeader.Rows)
{
FarPoint.Win.Spread.Cell cell = fpSpread1.ActiveSheet.RowHeader.Cells[row.Index, 0];
cell.Locked = true;
cell.Renderer = new GeneralCellType();
cell.LockForeColor = Color.Black;
cell.Border = new ComplexBorder(new ComplexBorderSide(ComplexBorderSideStyle.ThinLine, Color.LightGray));
}
Kindly refer to the attached sample for full implementation. (See Spread_ProtectedSheet.zip)
Also, why does the sheet have to be protected to have the Locked properties work?
As per the design behavior of Spread.NET control, the user can still interact with cells marked as locked when the Protect property is false. Therefore, it is required to enable the Protect property of the SheetView object to lock the cells it contains.
Please refer to the following link for more information regarding the same: https://www.grapecity.com/spreadnet/docs/latest/online-win/spwin-celllock.html
Finally, is there a way to have the behaviour of a locked cell without protecting the whole sheet?
Unfortunately, there is no other way to set the locked cells without protecting the whole sheet.
In case you are facing any particular issue because of protecting the whole sheet, kindly let us know.
Thanks & Regards,
Aastha