Articles in this section
Category / Section

How to set style properties for Read-Only cells in WinForms GridControl?

1 min read

Style property for read-only cells in grid

Setting a cell as ReadOnly enables ReadOnly for programmatic changes. Hence a cell set to ReadOnly cannot have any property changed (Text, BackColor, Font, ReadOnly) unless you specify to ignore the ReadOnly flag. To change a ReadOnly cell, you need to set grid.IgnoreReadOnly as true. Make necessary changes and then reset the IgnoreReadOnly property. Programmatically changing a cell value triggers the same change events that are triggered that means one event can handle the saving of all changes.

C#

//To make the cells readonly
this.gridControl1.TableStyle.Text = "Test";
this.gridControl1.TableStyle.BackColor = Color.LightPink;
this.gridControl1.TableStyle.ReadOnly = true;
this.gridControl1.TableStyle.Font.Bold = true;
//Free the cells from readonly
this.gridControl1.Model.IgnoreReadOnly = true;
this.gridControl1.TableStyle.Text = "Changed";
this.gridControl1.TableStyle.BackColor = Color.LightGreen;
this.gridControl1.TableStyle.Font.Bold = true;
//if you want to make it to read only again, reset the IgnoreReadOnly property.
this.gridControl1.Model.IgnoreReadOnly = false;

 

VB

'To make the cells readonly
Me.gridControl1.TableStyle.Text = "Test"
Me.gridControl1.TableStyle.BackColor = Color.LightPink
Me.gridControl1.TableStyle.ReadOnly = True
Me.gridControl1.TableStyle.Font.Bold = True
'Free the cells from readonly
Me.gridControl1.Model.IgnoreReadOnly = True
Me.gridControl1.TableStyle.Text = "Changed"
Me.gridControl1.TableStyle.BackColor = Color.LightGreen
Me.gridControl1.TableStyle.Font.Bold = True
'if you want to make it to read only again, reset the IgnoreReadOnly property.
Me.gridControl1.Model.IgnoreReadOnly = False

 

Samples:

C#: ReadOnlyCell

VB: ReadOnlyCell

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied