Geeks With Blogs
HanSolo code monkey
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 on Tuesday, September 15, 2009 12:30 AM | Back to top


Comments on this post: DataGridView upper case textbox column

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © HanSolo | Powered by: GeeksWithBlogs.net