Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void initializeColumnWidths()
- {
- //iterate through the columns in the grid
- foreach (DataGridViewColumn Col in customerDataGridView.Columns)
- {
- //if it's a text box column (this will skip dropdowns and checkboxes
- if (Col is DataGridViewTextBoxColumn)
- {
- //if the data type is string (not numeric or date)
- if (Col.ValueType == typeof(System.String))
- {
- //use the dataset on your form
- int maxlen = customerDataset.customer.Columns[Col.DataPropertyName].MaxLength;
- //optional: add the column width to the column header text
- Col.HeaderText += string.Format("({0})", maxlen);
- //Set the maxinputlength
- (Col as DataGridViewTextBoxColumn).MaxInputLength = maxlen;
- }
- }
- }
- //this should be repeated for every grid on your form.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement