Category / Section
How to protect or unprotect a selected range of formula cells in WinForms GridControl?
The selected ranges of formula cells are protected with the help of the ReadOnly Property in WinForms GridControl. To protect a selected range of cells by using the Mouse or Keyboard, click Tools->Protection-> Protect Cells. To unprotect a selected range of cells by using Mouse or Keyboard, click Tools->Protection->Unprotect Cells.
GridStyleInfo headerStyle = new GridStyleInfo();
private void menuItem7_Click(object sender, System.EventArgs e)
{
this.gridControl1.IgnoreReadOnly=false;
//To protect selected Formula Cells.
this.gridControl1.CurrentCell.MoveTo(-1,-1);
headerStyle.ReadOnly =true;
headerStyle.BackColor=Color.LightPink;
foreach(GridRangeInfo r in this.gridControl1.Selections.Ranges)
{
this.gridControl1.ChangeCells(r, headerStyle,Syncfusion.Styles.StyleModifyType.Override);
}
this.gridControl1.Selections.Clear();
}
private void menuItem8_Click(object sender, System.EventArgs e)
{
//To unprotect Selected Formula Cells.
this.gridControl1.CurrentCell.MoveTo(-1,-1);
this.gridControl1.IgnoreReadOnly=true;
headerStyle.ReadOnly = false;
headerStyle.BackColor=Color.White; //.FromKnownColor(System.Drawing.KnownColor.White);
foreach(GridRangeInfo r in this.gridControl1.Selections.Ranges)
{
this.gridControl1.ChangeCells(r, headerStyle,Syncfusion.Styles.StyleModifyType.Override);
}
this.gridControl1.IgnoreReadOnly=false;
this.gridControl1.Selections.Clear();
}Private headerStyle As New GridStyleInfo()
Private Sub menuItem7_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.gridControl1.IgnoreReadOnly=False
'To protect selected Formula Cells.
Me.gridControl1.CurrentCell.MoveTo(-1,-1)
headerStyle.ReadOnly =True
headerStyle.BackColor=Color.LightPink
For Each r As GridRangeInfo In Me.gridControl1.Selections.Ranges
Me.gridControl1.ChangeCells(r, headerStyle,Syncfusion.Styles.StyleModifyType.Override)
Next r
Me.gridControl1.Selections.Clear()
End Sub
Private Sub menuItem8_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'To unprotect Selected Formula Cells.
Me.gridControl1.CurrentCell.MoveTo(-1,-1)
Me.gridControl1.IgnoreReadOnly=True
headerStyle.ReadOnly = False
headerStyle.BackColor=Color.White '.FromKnownColor(System.Drawing.KnownColor.White);
For Each r As GridRangeInfo In Me.gridControl1.Selections.Ranges
Me.gridControl1.ChangeCells(r, headerStyle,Syncfusion.Styles.StyleModifyType.Override)
Next r
Me.gridControl1.IgnoreReadOnly=False
Me.gridControl1.Selections.Clear()
End SubAfter
applying the properties, the grid looks as follows.

Figure 1: Protect the selected range of formula cell
Samples: