Articles in this section
Category / Section

How to resolve the issue of AddNewRecord not working while navigating the ReadOnly column using Tab key?

1 min read

In GridDataBoundGrid if a specific column is set to read only, it cannot be edited. The AddNewRecord for the entire grid would not be achieved excluding the readonly column.

To achieve AddNewRecords to grid except the readonly column, you need to restrict the current cell using CurrentCellStartEditing and CurrentCellActivated event for that particular column.

C#

  //Event Handler
            this.gridDataBoundGrid1.CurrentCellStartEditing += gridDataBoundGrid1_CurrentCellStartEditing;
            this.gridDataBoundGrid1.CurrentCellActivated += gridDataBoundGrid1_CurrentCellActivated;
 
void gridDataBoundGrid1_CurrentCellActivated(object sender, EventArgs e)
        {
            
            if(gridDataBoundGrid1.CurrentCell.ColIndex == 2)
                this.gridDataBoundGrid1.CurrentCell.BeginEdit();
        }
 
        void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
        {
            //The edit mode for second column gets restricted.
            if(gridDataBoundGrid1.CurrentCell.ColIndex == 2)
            {
                this.gridDataBoundGrid1.CurrentCell.IsModified = true;
                e.Cancel = true;
            }
        }

 

VB

'Event Handler
Me.gridDataBoundGrid1.CurrentCellStartEditing += gridDataBoundGrid1_CurrentCellStartEditing
Me.gridDataBoundGrid1.CurrentCellActivated += gridDataBoundGrid1_CurrentCellActivated
 
Private Sub gridDataBoundGrid1_CurrentCellActivated(ByVal sender As Object, ByVal e As EventArgs)
 
 If gridDataBoundGrid1.CurrentCell.ColIndex = 2 Then
    Me.gridDataBoundGrid1.CurrentCell.BeginEdit()
 End If
 End Sub
 
Private Sub gridDataBoundGrid1_CurrentCellStartEditing(ByVal sender As Object, ByVal e As CancelEventArgs)
 'The edit mode for second column gets restricted.
 If gridDataBoundGrid1.CurrentCell.ColIndex = 2 Then
  Me.gridDataBoundGrid1.CurrentCell.IsModified = True
  e.Cancel = True
 End If
End Sub
 

 

Screenshot

add new record to Grid

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied