Share This!

Friday, June 10, 2011

How to make your DataGridView set maxInputLength based on the data cells.

This tutorial was created using:
Visual Studio 2010
SQL Server Express database
Visual C# language

I found that when you create a database and use a DataGridView, the column lengths for the string columns are all set to max.  This is unacceptable, as the user experience will be an error message AFTER they enter all their data and try to save.

It is an option to go through the DataGridView columns one at a time and set their Max InputLengths, but here, I want to show how to do this programmatically.  I perform this function on the load of the form, as the "Layout" even happens whenever you change from minimized to maximized, etc.

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

1 comment:

Contact Us


Email *

Message *