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:)
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Tuesday, September 15, 2009 12:30 AM
Print

Comments on this entry:

No comments posted yet.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910