How to restrict input in the textbox column in The datagridview.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.