Hi,
I'm trying to add a phone number column using the MaskedEditColumn and store it in a nullable double property of a business object, without the mask. However, the code is crashing the I'm leaving the cell with an exception about DataConversion. I found that the value that the grid is trying to set in the PhoneDouble property contains the mask, so the conversion fails. How can I make it work? I thought the MaskFormat = MaskFormat.ExcludePromptAndLiterals would fix that but it doesn't.
I'm using v.2013.1.220.40
Thanks!
--
Frank
I'm trying to add a phone number column using the MaskedEditColumn and store it in a nullable double property of a business object, without the mask. However, the code is crashing the I'm leaving the cell with an exception about DataConversion. I found that the value that the grid is trying to set in the PhoneDouble property contains the mask, so the conversion fails. How can I make it work? I thought the MaskFormat = MaskFormat.ExcludePromptAndLiterals would fix that but it doesn't.
I'm using v.2013.1.220.40
Thanks!
--
Frank
public static class GridUtils{ public static GridViewMaskBoxColumn AddPhoneNumberColumn(this RadGridView grid, string uniqueName, string fieldName, string headerText, Type type) { GridViewMaskBoxColumn col = new GridViewMaskBoxColumn(); col.Name = uniqueName; col.FieldName = fieldName; col.HeaderText = headerText; col.MaskType = MaskType.Standard; col.Mask = "(000) 000-0000"; col.FormatString = "{0:(###) ###-####}"; col.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; col.DataType = type; grid.Columns.Add(col); return col; }}public class Form2 : Form{ private BindingList<TestClass> _dataSource; public class TestClass { private string _string; private double? _double; public string PhoneString { get { return this._string; } set { this._string = value; } } public double? PhoneDouble { get { return this._double; } set { this._double = value; } } } public Form2() { InitializeComponent(); this.radGridView1.AutoGenerateColumns = false; this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; this.radGridView1.AddPhoneNumberColumn("stringMasked", "PhoneString", "PhoneStringMasked", typeof(string)); this.radGridView1.AddPhoneNumberColumn("doubleMasked", "PhoneDouble", "PhoneDoubleMasked", typeof(double?)); this._dataSource = new BindingList<TestClass>(); this._dataSource.Add(new TestClass() { PhoneDouble = 5554443333, PhoneString = "5554443333" }); this.radGridView1.DataSource = this._dataSource; } #region Designer /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.radGridView1 = new Telerik.WinControls.UI.RadGridView(); ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit(); this.SuspendLayout(); // // radGridView1 // this.radGridView1.Dock = System.Windows.Forms.DockStyle.Fill; this.radGridView1.Location = new System.Drawing.Point(0, 0); this.radGridView1.Name = "radGridView1"; this.radGridView1.Size = new System.Drawing.Size(607, 284); this.radGridView1.TabIndex = 0; this.radGridView1.Text = "radGridView1"; // // Form2 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(607, 284); this.Controls.Add(this.radGridView1); this.Name = "Form2"; this.Text = "Form2"; ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit(); this.ResumeLayout(false); } private Telerik.WinControls.UI.RadGridView radGridView1; #endregion #endregion}