Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear sir,

I have a datagridview on form in window application. I want to restrict the length of the characters of the any one column of a datagridview.
Posted
Updated 9-Nov-18 8:35am

Use the MaxInputLength property of the DataGridViewTextBoxColumn.
This property is available through the Designer or through code:
C#
((DataGridViewTextBoxColumn)dataGridView1.Columns[yourColumn]).MaxInputLength = 6
 
Share this answer
 
Comments
Ashwini kumbhar 2-Aug-13 2:59am    
but if u enter less than 6 numbers then automatically this column show empty means this column is not accepted less than 6 numbers.
CType(Me.DGV_contas2.Columns(NumeroDaColuna), DataGridViewTextBoxColumn).MaxInputLength = 9


CType(Me.DGV_contas2.Columns(3), DataGridViewTextBoxColumn).MaxInputLength = 9
 
Share this answer
 
Comments
Richard Deeming 9-Nov-18 15:22pm    
As already covered in solution #1, back in 2013.
vbnet

CType(Me.DGV_contas2.Columns(3), DataGridViewTextBoxColumn).MaxInputLength = 9
 
Share this answer
 
Comments
Richard Deeming 9-Nov-18 15:23pm    
If you want to update your solution, click the green "Improve solution" link and edit your solution. DO NOT post the update as a second solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900