New to Telerik UI for WinForms? Start a free 30-day trial
Limiting the text length in RadGridView's cell
Updated over 6 months ago
| Product Version | Product | Author | Last modified |
|---|---|---|---|
| Q2 2009 SP1 | RadGridView for WinForms | Nikolay Diyanov | May 23, 2012 |
PROBLEM
Limit the text length in RadGridView's text column when it is in edit mode
SOLUTION
If you need to limit the text length when typing a new value in a text column cell, the best way is to prevent the user from typing more symbols than allowed. This can be done by setting the MaxLength propertyof RadTextBoxEditor's RadTextBoxEditorElement:
C#
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
if (e.ColumnIndex == 4)
{
if (e.Column is GridViewTextBoxColumn)
{
((RadTextBoxEditorElement)((RadTextBoxEditor)this.radGridView1.ActiveEditor).EditorElement).MaxLength = 30;
}
}
}