Articles in this section

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

Style property for read-only cells in the 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 read-only cell, you need to set the 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, which means one event can handle the saving of all changes.


//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;
'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 (0)
Access denied
Access denied