)
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 ReadOnly in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: February 9, 2015 |
Last Revised Date: February 12, 2020
Tags: styling, readonly

Make the cells into readonly

In GridGroupingControl, you can make the cell read-only by setting the ReadOnly Property in the Grid model or by using the QueryCellStyleInfo Event.

By using GridModel

C#

//  Column can be index or column MappingName 
gridGroupingControl1.TableDescriptor.Columns[Column].Appearance.AnyRecordFieldCell.ReadOnly = true;

VB

' Column can be index or column MappingName 
gridGroupingControl1.TableDescriptor.Columns(Column).Appearance.AnyRecordFieldCell.ReadOnly = True

By using QueryCellStyleInfo

C#

void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
 // The cell is set to be Readonly
 if (e.TableCellIdentity.RowIndex == 6 && e.TableCellIdentity.ColIndex == 3)
 {
  e.Style.BackColor = Color.Yellow;
  e.Style.ReadOnly = true;
 }
 // The row is set to be Readonly
 if (e.TableCellIdentity.RowIndex == 4)
 {
  e.Style.BackColor = Color.LightGray;
  e.Style.ReadOnly = true;
 }
 // The Column is set to be Readonly using index
 if (e.TableCellIdentity.ColIndex == 4)
 {
  e.Style.BackColor = Color.Aqua;
  e.Style.ReadOnly = true;
 }
 // The Column is set to be Readonly using  Column MappingName
 if (e.TableCellIdentity.Column!= null)
 {
  if (e.TableCellIdentity.Column.Name == "City")
  {
   e.Style.BackColor = Color.Aqua;
   e.Style.ReadOnly = true;
  }
 }
 //Range of cell is set to be Readonly
 if ((e.TableCellIdentity.RowIndex == 7 || e.TableCellIdentity.RowIndex == 8) &&  (e.TableCellIdentity.ColIndex == 1 || e.TableCellIdentity.ColIndex == 2))
 {
  e.Style.BackColor = Color.LightPink;
  e.Style.ReadOnly = true;
 }
}

VB

Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs)
 ' The cell is set to be Readonly
 If e.TableCellIdentity.RowIndex = 6 AndAlso e.TableCellIdentity.ColIndex = 3 Then
  e.Style.BackColor = Color.Yellow
  e.Style.ReadOnly = True
 End If
 ' The row is set to be Readonly
 If e.TableCellIdentity.RowIndex = 4 Then
  e.Style.BackColor = Color. LightGray
  e.Style.ReadOnly = True
 End If
 ' The Column is set to be Readonly using index
 If e.TableCellIdentity.ColIndex = 4 Then
  e.Style.BackColor = Color.Aqua
  e.Style.ReadOnly = True
 End If
 ' The Column is set to be Readonly using Column MappingName
 If e.TableCellIdentity.Column IsNot Nothing Then
  If e.TableCellIdentity.Column.Name = "City" Then
   e.Style.BackColor = Color.Aqua 
   e.Style.ReadOnly = True
  End If
 End If
 'Range of cell is set to be Readonly
 If (e.TableCellIdentity.RowIndex = 7 OrElse e.TableCellIdentity.RowIndex = 8) AndAlso (e.TableCellIdentity.ColIndex = 1 OrElse e.TableCellIdentity.ColIndex = 2) Then
  e.Style.BackColor = Color. LightPink
  e.Style.ReadOnly = True
 End If
End Sub

The following screenshot displays the grid after applying the properties.

Make the cells into readonly

Figure 1: Make the cells into ReadOnly

Note:

The read-only cells are shown in different colors

Samples:

C#: Read-Only Cell

VB: Read-Only Cell

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