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

RadTextBoxElement Max Length Property

1 Answer 259 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Duang
Top achievements
Rank 1
Duang asked on 11 Sep 2008, 10:22 AM
 Hi,
    I have to added a custom elements (RadTextBoxElement) to grid cells on the CellFormatting event at runtime.
RadTextBoxElement textbox = new RadTextBoxElement();  
textbox.Alignment = ContentAlignment.MiddleCenter;  
textbox.KeyPress += new KeyPressEventHandler(textbox_KeyPress);  
textbox.TextChanged += new EventHandler(textbox_TextChanged);  
e.CellElement.Children.Add(textbox); 

    I would like to limit the value of textbox not over 99 but i can't set the max length property of the RadTextBoxElement.
Can you help me for solve this problem ?

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 12 Sep 2008, 04:18 PM
Hello Duang,

Thank you for writing.

Adding RadTextBoxElement to RadGridView is not a good practice, because the RadGridView behavior may become unpredictable. Is there are a particular reason for going this route?

I would suggest using a standard GridViewTextBoxColumn. You could limit the text length by accessing TextBox in RadTextBoxEditor and set its MaxLenght property. Please, review the code-block below as example:
 
private void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e) 
    if (this.radGridView1.ActiveEditor is RadTextBoxEditor) 
    { 
        //limit the lenght only for column with index 4 
        if (e.ColumnIndex == 4) 
        { 
            ((this.radGridView1.ActiveEditor as RadHostItem).HostedControl as TextBox).MaxLength = 5; 
        } 
        else 
        { 
            ((this.radGridView1.ActiveEditor as RadHostItem).HostedControl as TextBox).MaxLength = 32767; 
        } 
    } 

I hope this helps.

Best wishes,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Duang
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or