Search code examples
silverlightgridviewtelerikmaxlength

Silverlight Telerik GridView MaxLength?


Im using a telerik gridview for silverlight and Im trying to programatically set the maximum character length on each individual column after the gridview is populated with data. I want to make it so when the user is inserting or editing a column's cell, the maximum (char) length is set based on a control records max length. So far Ive only been able to set the MaxWidth, but that doesnt help me because the column header is always longer than the atual text allowed, and the MaxWidth sets the column width in pixels, not the columns editing max character length. Can someone point me in the right direction. I can provide some code if need be.

Ive tried setting it to column.CellEditTemplate.SetValue(TextBoxEditor.MaxLengthProperty, MYMAXLENGTH);

but it gives me an error.


Solution

  • How about something like this?

    Style textBoxStyle = new Style(typeof(TextBox));
    textBoxStyle.Setters.Add(new Setter(TextBox.MaxLengthProperty, myMaxLength));
    (this.MyGrid.Columns[0] as GridViewBoundColumnBase).EditorStyle = textBoxStyle;
    

    http://www.telerik.com/community/forums/silverlight/gridview/best-way-to-set-maxlength-on-gridviewdatacolumn.aspx