Link to home
Start Free TrialLog in
Avatar of MKItani

asked on

Howi can add MaskedTexbox column to dataGridView+C#(Windows Application

We use C#(Windows Application)
please u can send me a code to know how i can add a MaskedTextBox Column to Datagridview.
Avatar of guvera
Flag of India image


Please check the code.

private void BuildGrid(DataGridView dgv, DataTable dt)
                    MaskedTextBoxColumn mtbc = new MaskedTextBoxColumn();
                    mtbc.DataPropertyName ="Date";
                    mtbc.Mask = "00/00/0000";
                    mtbc.HeaderText = Header;
                    mtbc.Width = 20;
                    mtbc.Tag = "d";
                    mtbc.ValidatingType = typeof(ZipCode);

dgv.Datasource = dt


public class MaskedTextBoxColumn : DataGridViewColumn
        public override object Clone()

            MaskedTextBoxColumn col =


            col.Mask = this.Mask;

            return col;


        …….other code


Also check this link for generic grid view. One of the module is masked textbox in grid view. Source code available in the link.

Avatar of MKItani


the code doesn't work because the compiler cannot recognize on keyword "Mask"

so what i should to do?
There is nothing called MaskedTextBoxColumn or even Masked TextBox in .NET.
If you want to use one, you will have to use AJAX Extenders to do the same. If you wish to use Ajax Extenders you can download the same from this link:

The above link will give you access to AJAX Toolkit and Extenders. Do download the AJAX Extenders.
Then you can use the Masked Text Box
Avatar of MKItani


i am building  (window application) and no website(, so i want to ask you "the AJAX Extenders"
can work on window application?
Oops, my mistake. :)

No the AJAX extenders won't work with Windows Apps. I will give you the code shortly.. Give me sometime..
There is no Masked TextBox available for Windows Form as well. If you want one, kindly download the control from the following link:

See if it suffice your requirements.

Once you have the control, you can follow the steps given by 'guvera' and just replace the MaskedTextBox by the downloaded control name.

If any issue, let me know.
Avatar of MKItani


i think u don't understand yet what i am asked, i want to add a masked textbox "Column" to "dataGridView"
(C# Widow application)
i am waiting for your response
I understand that. Do you have a MAsked Text Box Control already? As far as I know .NET framework does not provide the MAsked Text Box control.
My mistake, just checked, .NET 4.0 has a masked text box control.
Please ignore my previous posts on this.  I am trying to write a code snippet for you. Will post here in a while.
Avatar of MKItani


sure dot net involves a simple Masked Text Box control but how i can add Masked textBox Column
to DatagridView.
Please check the behavior by creating a simple project C# on Visual studio 2008
i am waiting for your response.
Avatar of lazyberezovsky
Flag of Belarus image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial