Link to home
Start Free TrialLog in
Avatar of MKItani
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
guvera
Flag of India image

Hi,

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.Columns.Add(mtbc);


dgv.Datasource = dt

}

public class MaskedTextBoxColumn : DataGridViewColumn
{
       
        public override object Clone()
        {

            MaskedTextBoxColumn col =

                (MaskedTextBoxColumn)base.Clone();

            col.Mask = this.Mask;

            return col;

        }

        …….other code
}

Thanks
Guvera

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

http://www.codeproject.com/KB/miscctrl/GenericDataGridView.aspx

Thanks
Guvera
Avatar of MKItani
MKItani

ASKER

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:

http://ajaxcontroltoolkit.codeplex.com/releases/view/43475

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

ASKER

i am building  (window application) and no website(Asp.net), 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:

http://www.csharphelp.com/2006/04/masked-c-textbox-control/

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

ASKER

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

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of lazyberezovsky
lazyberezovsky
Flag of Belarus image

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