limit length on gridview column

2 posts, 0 answers
  1. Donna
    Donna avatar
    8 posts
    Member since:
    Jun 2016

    Posted 12 Jun 2017 Link to this post

    How can I limit the length of characters user can enter on a particular gridview column?

    I tried this code but I got an error saying that there is no definition for MaxLength?


    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)     
        if (e.ColumnIndex == 1)  
            if (e.Column is GridViewTextBoxColumn)     
                ((RadTextBoxEditorElement)((RadTextBoxEditor)this.radGridView1.ActiveEditor).EditorElement).MaxLength = 30;     

  2. Dimitar
    Dimitar avatar
    2831 posts

    Posted 13 Jun 2017 Link to this post

    Hello Donna,

    Here is how you can set the MaxLength:
    private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        var editor = e.ActiveEditor as RadTextBoxEditor;
        if (editor != null)
            var element = editor.EditorElement as RadTextBoxEditorElement;
            element.TextBoxItem.MaxLength = 30;

    I hope this will be useful. Let me know if you have additional questions.

    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top