The datagridview is a new data control of. net2.0, which is much more powerful than the DataGrid. However, there is no cellkeypress event to restrict the input of text columns. I used a newly added event editcontrolshowing to solve this problem. Private Editingcontrol As Datagridviewtextboxeditingcontrol
Private Sub datagridview1_editingcontrolshowing () Sub Datagridview1_editingcontrolshowing ( Byval Sender As Object , Byval E As System. Windows. Forms. datagridvieweditingcontrolshowingeventargs) Handles Datagridview1.editingcontrolshowing
Editingcontrol = Ctype (E. Control, datagridviewtextboxeditingcontrol)
Addhandler Editingcontrol. keypress, Addressof Editingcontrol_keypress
End sub
Public Sub editingcontrol_keypress () SubEditingcontrol_keypress (ByvalSenderAsSystem. object,ByvalEAsKeypresseventargs)
'Write the processing statement
End sub
Private Sub maid () Sub Maid ( Byval Sender As Object , Byval E As System. Windows. Forms. datagridviewcelleventargs) Handles Datagridview1.cellendedit
Removehandler Editingcontrol. keypress, Addressof Editingcontrol_keypress
End sub
In this way, the problem of Restricted input can be solved, and many other problems can be solved through this method.