DataGridView upper case textbox column

It's a shame that the DataGridViewTextBoxColumn class doesn't allow you to set the casing so that you can restrict user input to all upper or lower case letters.

Fortunately, it's actually pretty easy to create a custom column class to do just that.
public class DataGridViewUpperCaseTextBoxColumn : DataGridViewTextBoxColumn
{
    public DataGridViewUpperCaseTextBoxColumn()
        : base()
    {
        CellTemplate = new DataGridViewUpperCaseTextBoxCell();
    }
}
 
public class DataGridViewUpperCaseTextBoxCell : DataGridViewTextBoxCell
{
    public DataGridViewUpperCaseTextBoxCell()
        : base()
    {
    }
 
    public override Type EditType
    {
        get
        {
            return typeof(DataGridViewUpperCaseTextBoxEditingControl);
        }
    }
}
 
public class DataGridViewUpperCaseTextBoxEditingControl : DataGridViewTextBoxEditingControl
{
    public DataGridViewUpperCaseTextBoxEditingControl()
        : base()
    {
        this.CharacterCasing = CharacterCasing.Upper;
    }
}

Sweet fancy moses:)
posted @ Tuesday, September 15, 2009 12:30 AM
Print

Comments on this entry:

No comments posted yet.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«May»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678