Articles in this section
Category / Section

How do I make the cells as ReadOnly in GridDataBoundGrid?

2 mins read

GridDataBoundGrid allows you to make the cell read-only by setting the ReadOnly property in the Grid model, or using the QueryCellInfo event.

Using GridModel

C#

//Apply Readonly to column 1
this.gridDataBoundGrid1.Binder.InternalColumns[1].StyleInfo.ReadOnly = true;

VB

'Apply Readonly to column 1
Me.gridDataBoundGrid1.Binder.InternalColumns(1).StyleInfo.ReadOnly = True

Using QueryCellInfo

C#

void Model_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
{
//Apply Readonly to cell(3,3)
if (e.RowIndex == 3 && e.ColIndex == 3)
{
e.Style.BackColor = Color.Yellow;
e.Style.ReadOnly = true;
}
// Apply ReadOnly to Row 4
if (e.RowIndex == 4)
{
e.Style.BackColor = Color.Blue;
e.Style.ReadOnly = true;
}
// Apply ReadOnly to Column 4
if (e.ColIndex == 4)
{
e.Style.BackColor = Color.Aqua;
e.Style.ReadOnly = true;
}
// Apply ReadOnly to Range of cells
if ((e.RowIndex == 1 || e.RowIndex == 2) && (e.ColIndex == 1 || e.ColIndex == 2))
{
e.Style.BackColor = Color.Red;
e.Style.ReadOnly = true;
}
}

VB

Private Sub Model_QueryCellInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs)
'Apply Readonly to cell(3,3)
If e.RowIndex = 3 AndAlso e.ColIndex = 3 Then
e.Style.BackColor = Color.Yellow
e.Style.ReadOnly = True
End If
' Apply ReadOnly to Row 4
If e.RowIndex = 4 Then
e.Style.BackColor = Color.Blue
e.Style.ReadOnly = True
End If
' Apply ReadOnly to Column 4
If e.ColIndex = 4 Then
e.Style.BackColor = Color.Aqua
e.Style.ReadOnly = True
End If
'Apply ReadOnly to Range of cells
If (e.RowIndex = 1 OrElse e.RowIndex = 2) AndAlso (e.ColIndex = 1 OrElse e.ColIndex = 2) Then
e.Style.BackColor = Color.Red
e.Style.ReadOnly = True
End If

After applying the properties, the cell is displayed as follows,

Query Cell Style Info

Figure 1: Make the cells as read-only

Note:

The changes of the cells are shown in different colors.

 

Sample Links

CS: Make the cells read-only

VB: Make the cells read-only

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