How to make the cells ReadOnly in WinForms GridGroupingControl?
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.
Figure 1: Make the cells into ReadOnly
The read-only cells are shown in different colors
Samples:
C#: Read-Only Cell
VB: Read-Only Cell
Conclusion
I hope you enjoyed learning about how to make the cells ReadOnly in WinForms GridGroupingControl.
You can refer to our WinForms Grid feature
tour page to know
about its other groundbreaking feature representations. You can also
explore our
WinForms
Grid documentation to
understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!