Category / Section
How do I make the cells as ReadOnly in GridDataBoundGrid?
1 min 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,
Figure 1: Make the cells as read-only
Note:
The changes of the cells are shown in different colors.
Sample Links