Rest Part
using JThomas.Controls;
create a new column and set a mask using a minimum of 4 and a maximum of 7 digits
DataGridViewMaskedTextColumn column = new DataGridViewMaskedTextColumn("0000999");
column.DataPropertyName = "Number";
column.HeaderText = "Nummer"; // German text
column.Name = "column";
column.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
column.Width = 70;
// add this column to the DataGridView dgv
dgv.Columns.Add(column);
Working by Designer
After adding the reference to the ExtendedControls.dll assembly, you can open the IDE and select a DataGridViewMaskedTextColumn as DataGridViewColumn – either in the Edit Columns window, like in the image above, or in the Add Column window. There you can set the Mask string.
Mask Details
Check all Mask possibilities in the SDK documentation for the MaskedTextBox.Mask property.
Vijay Kumar