This is a migrated thread and some comments may be shown as answers.

force user text ToUpper() in TextBox Columnr?

3 Answers 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jstott
Top achievements
Rank 1
jstott asked on 01 Feb 2011, 07:06 AM
I'm looking for an right approach to both limit and alter the text being typed in a textbox column?

For the given cell column, I'd need to limit the user input to a range of characters (A-E,0-9), but also auto-uppercase the values as they are being typed in?  I've also tried to split the validation and uppercase portions in two separate events, but the real-time uppercase always seems to get me stuck.

I've looked at ValueChanging, as its raised for each keystroke, but changing the cell value within this event causes a stackoverflow, and changing the e.NewValue does not have any effect.

I've also tried CellFormatting - but that only formats the text after the edit is completed.
Thoughts?

3 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 01 Feb 2011, 10:53 AM
Hello,

In order to provide upper casing to your text editor in the grid, and to ensure that current text is displayed in upper case you can handle the CellFormatting and CellEditorInitialized events.

this.radGridView1.CellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.radGridView1_CellFormatting);
this.radGridView1.CellEditorInitialized += new Telerik.WinControls.UI.GridViewCellEventHandler(this.radGridView1_CellEditorInitialized);
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadTextBoxEditor tbEditor = this.radGridView1.ActiveEditor as RadTextBoxEditor;
    if (tbEditor != null)
    {
        RadTextBoxEditorElement tbElement = (RadTextBoxEditorElement)tbEditor.EditorElement;
        tbElement.CharacterCasing = CharacterCasing.Upper;
    }
}
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement is GridDataCellElement)
    { e.CellElement.Text = e.CellElement.Text.ToUpperInvariant(); }
}

For ensuring that the text inout is validated, there are several ways to do this, but I would suggest having a look at my Code Library Article here on using IDataErrorInfo and combine this with  regular expressions

Hope that helps
Richard
0
jstott
Top achievements
Rank 1
answered on 01 Feb 2011, 08:20 PM
Thank you - that worked out perfect!
0
Richard Slade
Top achievements
Rank 2
answered on 01 Feb 2011, 08:39 PM
Glad I could be of help. Richard
Tags
GridView
Asked by
jstott
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
jstott
Top achievements
Rank 1
Share this question
or