To make a single cell or multiple cells read-only, use the BeforeEdit event.
You can make any cell in the grid read-only so that the data within it cannot be changed. For example, enter the following code to make the cell in column 1, row 1 read-only:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1FlexGrid1_BeforeEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles C1FlexGrid1.BeforeEdit If e.Row = 1 And e.Col = 1 Then e.Cancel = True End If End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1FlexGrid1_BeforeEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e) { if (e.Row == 1 & e.Col == 1) { e.Cancel = true; } } |
You may also want to set multiple cells in the grid to read-only at one time. Suppose you have an editable grid used to enter customers' information, such as customer IDs, addresses, and orders. While the orders and addresses may change, the customer IDs will not. The code below assumes you have nine rows in your grid, and you would like to make all of the rows in the first column, the Customer ID column, read-only. Enter the following code:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1FlexGrid1_BeforeEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles C1FlexGrid1.BeforeEdit Dim i As Integer For i = 1 To 9 If e.Col = 1 And e.Row = i Then e.Cancel = True End If Next End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1FlexGrid1_BeforeEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e) |
Notice that none of the cells in the Customer ID column are editable.