Nullable TextBox bound to numeric column

4 posts, 0 answers
  1. Piotr
    Piotr avatar
    1 posts
    Member since:
    May 2011

    Posted 18 May 2011 Link to this post


    I have a RadMaskedEditBox bound to BindingSource which is connected to some column with numeric (Int32) in DataTable in some DataSource.
    Values are properly displayed in the control, but I want users to be able to nullify the column value in the table
    by deleting existing value from the RadMaskedEditBox and leaving it empty.
    Is there any way of configuring RadMaskedEditBox to achieve this? Or maybe some other control is better for the job?
    This feature does not exist in standard WinForms TextBox and I am currently searching for the controls that would do that task without any tweaking etc.

  2. Peter
    Peter avatar
    1148 posts

    Posted 23 May 2011 Link to this post

    Hi Piotr,

    Thank you for the question.

    Our current implementation of RadMaskedEditBox does not support null values and cannot be used in this scenario. However, this is a nice feature and I added it in our feature requests list. We will consider it when implementing the next version of this control.

    If you have any additional questions, do not hesitate to ask.

    Best wishes, Peter
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  3. Jan
    Jan avatar
    1 posts
    Member since:
    Mar 2013

    Posted 06 Mar 2013 Link to this post


    I need this same kind of behavior for my maskededitbox.
    I want the user to be able to enter a number in "n2" numeric format but wish to allow the user to clear the field, setting the bound property to null.

    Is there any change in this or is this still impossible?


  4. Peter
    Peter avatar
    1148 posts

    Posted 07 Mar 2013 Link to this post

    Hello Jan,

    Thank you for writing:

    The numeric masks does not provide a support for nullable values. However, you can try to achieve the requested behavior by setting 
    explicitly the Value of the MaskedEditBox to Null. For example you can add next to the MaskedEditBox a button that clears the value:
    Private Sub RadButton1_Click(sender As System.Object, e As System.EventArgs) Handles RadButton1.Click
        Me.RadMaskedEditBox1.Value = Nothing
    End Sub

    Or you can handle the KeyDown event and if the key is the Delete key and the user selected the whole text in the editor to set the Value to null:
    Sub key_Down(s As Object, e As KeyEventArgs) Handles RadMaskedEditBox1.KeyDown
        If e.KeyCode = Keys.Delete Then
            If Me.RadMaskedEditBox1.SelectionLength = Me.RadMaskedEditBox1.Text.Length Then 'the all text is selected and press del
                Me.RadMaskedEditBox1.Value = Nothing
            End If
        End If
    End Sub

    Please bear in mind that the Numeric masks are not designed and tested to work with NULL values and we do not guarantee that they will work correctly in all possible cases - for example this will not work if the user deletes the text with the Backspace button or when the user presses the Delete button without selecting the whole text.

    Please, refer to the attached project.

    I hope this helps.

    Kind regards,
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top