Limiting the text length in RadGridView's cell

Article Info

Rating: 1

Article information

Article relates to

RadControls for WinForms Q2 2009 SP1 

Created by

Martin Vassilev

Last modified

Oct 1, 2008

Last modified by

Nikolay Diyanov


HOW-TO

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:

VB code:
Private Sub radGridView1_CellEditorInitialized(ByVal sender As ObjectByVal e As GridViewCellEventArgs)  
    If e.ColumnIndex = 4 Then 
        If TypeOf e.Column Is GridViewTextBoxColumn Then 
            CType((CType(Me.radGridView1.ActiveEditor, RadTextBoxEditor)).EditorElement, RadTextBoxEditorElement).MaxLength = 30  
        End If 
    End If 
End Sub 

C# code:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)     
{     
    if (e.ColumnIndex == 4)  
    {  
        if (e.Column is GridViewTextBoxColumn)     
        {     
            ((RadTextBoxEditorElement)((RadTextBoxEditor)this.radGridView1.ActiveEditor).EditorElement).MaxLength = 30;     
        }     
    }  

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.