Click here to Skip to main content
16,017,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey there,

I need your help. I design my DataGridView 'Grid' with MaxInputLength in a specific column = 3. When I execute my project there's no problem when I insert info into my Grid, when I want to edit some saved info, I recover it from database MySQL doing this:

// RecoverDBase() is a BindingSource type method
Grid.DataSource = RecoverDBase();



I have no problem here. But when I insert text in this column, I can do it infinitely. I wouldn't have this problem if I can do something like this:

Grid.DataSource = RecoverDBase();
Grid.Columns[0].MaxInputLength=3;


But I can't. It doesn't exist something like that. How can I control the input text length after recovering a database like I do?¿
Posted
Updated 21-Apr-16 0:49am

You're probably going to have to write code to trim the string and add an elipse to indicate more text, but I thought that was already done for you by the control, and was based on how wide the associated column is.
 
Share this answer
 
When you bind a data grid view, the column becomes a DataGridViewTextBoxColumn object. It's this you should reference, as it is this that has the MaxInputLength property.

So if your column name is "Description", for instance, the object's name should automatically be something like "descriptionDataGridViewTextBoxColumn" (well, this happens for me in .NET).
 
Share this answer
 
You can try this :

C#
DataGridViewTextBoxColumn cName = (DataGridViewTextBoxColumn)dataGridView1.Columns[1];//here index of column
cName.MaxInputLength = 10;//here Max Length to column
 
Share this answer
 
v2

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