I created a support ticket and asked the following question:
I am binding a RadGridView to a SQL Server table.
The code below returns the following Data Exception Error:
Cannot set column 'SSAN'. The value violates the MaxLength limit of this column.
The SSAN field is a varchar(9). It should store 111223333 and not 111-22-3333. How can I set the column to save the text without the literals?
Dim col As GridViewMaskBoxColumn = New GridViewMaskBoxColumnWith col .Name = "SSAN2" .FieldName = "SSAN" .HeaderText = "SSN" .MaskType = MaskType.Standard .Mask = "000-00-0000" .TextAlignment = ContentAlignment.MiddleCenter .DataType = GetType(String) '.FormatString = "{0:000-00-0000}"End WithRadGridView1.MasterTemplate.Columns.Add(col)Svett from Telerik answered with the following:
You can achieve that by creating a custom editor:
Public Class CustomMaskedEditor Inherits RadMaskedEditBoxEditor Public Overrides Property Value() As Object Get Dim value__1 As Object = MyBase.Value value__1 = Convert.ToString(value__1).Replace("-", String.Empty) Return value__1 End Get Set MyBase.Value = value__1 End Set End PropertyEnd ClassThen you should use the EditorRequired event of RadGridView to replace the default one:
Private Sub radGridView1_EditorRequired(sender As Object, e As EditorRequiredEventArgs) If e.EditorType = GetType(RadMaskedEditBoxEditor) Then e.EditorType = GetType(CustomMaskedEditor) End IfEnd SubI did not realize that my ticked had been closed because of my delayed response and I asked Svett if the following would not also be a solution:
Imports Telerik.WinControls.UIPublic Class CustomMaskedEditor Inherits RadMaskedEditBoxEditor Public Overrides Sub BeginEdit() MyBase.MaskTextBox.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals MyBase.BeginEdit() Me.EditorElement.Focus() End SubEnd ClassCan anyone tell me if this is not an acceptable way to only have the numbers saved to the database?