)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to make the cells into readonly in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: February 9, 2015 |
Last Revised Date: December 18, 2019
Tags: styling, readonly

Set the cell into readonly

In GridControl, you can make the cell as read only by setting the ReadOnly Property in the GridModel or by using the QueryCellInfo Event

Using GridModel

C#

//particular cell is set to be ReadOnly
gridControl1[3, 3].BackColor = Color.Yellow;
gridControl1[3, 3].ReadOnly = true;
//Using GridRangeInfo, Range of cells is set to be ReadOnly
GridStyleInfo style = new GridStyleInfo();
style.ReadOnly = true;
style.BackColor = Color.Red;
this.gridControl1.ChangeCells(GridRangeInfo.Cells(1, 1, 2, 2), style);
//Using GridRangeInfo,the row is set to be Readonly
style.BackColor = Color.Blue;
this.gridControl1.ChangeCells(GridRangeInfo.Row(4), style);
//Using GridRangeInfo, The Column is set to be Readonly
style.BackColor = Color.Aqua;
this.gridControl1.ChangeCells(GridRangeInfo.Col(4), style);

 

VB

'particular cell is set to be ReadOnly
gridControl1(3, 3).BackColor = Color.Yellow
gridControl1(3, 3).ReadOnly = True
'Using GridRangeInfo, Range of cells is set to be ReadOnly
Dim style As New GridStyleInfo()
style.ReadOnly = True
style.BackColor = Color.Red
Me.gridControl1.ChangeCells(GridRangeInfo.Cells(1, 1, 2, 2), style)
'Using GridRangeInfo,the row is set to be Readonly
style.BackColor = Color.Blue
Me.gridControl1.ChangeCells(GridRangeInfo.Row(4), style)
'Using GridRangeInfo, The Column is set to be Readonly
style.BackColor = Color.Aqua
Me.gridControl1.ChangeCells(GridRangeInfo.Col(4), style)

 

Using QueryCellInfo

C#

void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
    // particular cell is set to be ReadOnly
    if (e.RowIndex == 3 && e.ColIndex == 3)
    {
        e.Style.BackColor = Color.Yellow;
        e.Style.ReadOnly = true;
    }
    //Using GridRangeInfo,the row is set to be Readonly
    if (e.RowIndex == 4)
    {
        e.Style.BackColor = Color.Blue;
        e.Style.ReadOnly = true;
    }
    //Using GridRangeInfo, The Column is set to be Readonly
    if (e.ColIndex == 4)
    {
        e.Style.BackColor = Color.Aqua;
        e.Style.ReadOnly = true;
    }
    //Using GridRangeInfo, Range of cells is set to be ReadOnly
    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 gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
' particular cell is set to be ReadOnly
    If e.RowIndex = 3 AndAlso e.ColIndex = 3 Then
        e.Style.BackColor = Color.Yellow
        e.Style.ReadOnly = True
    End If
    'Using GridRangeInfo,the row is set to be Readonly
    If e.RowIndex = 4 Then
        e.Style.BackColor = Color.Blue
        e.Style.ReadOnly = True 
    End If
    'Using GridRangeInfo, The Column is set to be Readonly
    If e.ColIndex = 4 Then
        e.Style.BackColor = Color.Aqua
        e.Style.ReadOnly = True
    End If
    'Using GridRangeInfo, Range of cells is set to be ReadOnly
    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
End Sub

 

The following screenshot displays the grid after applying the properties.

Set cells into readonly

Figure 1: Make the cells into ReadOnly

Note:

The read-only cells are shown in different colors.

 

Samples:

C#: ReadOnlyCells

VB: ReadOnlyCells

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
Live Chat Icon