We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I make the cells as ReadOnly in GridDataBoundGrid?

Platform: WinForms |
Control: GridDataBoundGrid(Classic)
Tags: styling, readonly

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile