Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 793103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:05:57+00:00 2026-05-14T22:05:57+00:00

I have extended a MaskedTextBox component to add some functionality. The text property of

  • 0

I have extended a MaskedTextBox component to add some functionality. The text property of the extended MaskedTextBox is bound to a DateTime? property and the format of binding is set to a time format of “HH:mm:ss” (i.e. 24hr time). So that this masked text box will capture the display a time.

The extra functionality I have added is to make the component readonly unless the component is double clicked or the enter button is pressed (the back color of the control helps to inform the users if the component is locked/readonly or not). When the enter button is pressed I also suspend the bindings so that bound data is updated the users input won’t be lost. The information is then written back to the value and databindings resumed when the user presses the enter key again.

This all works fine up to here, with values written and displayed as would be expected.

However, I also want to write the null or nothing value to the DateTime? property if the user hasn’t entered any text (or invalid text but let’s just stick with no text) when enter key is pressed to submit the new value.

Unlike with other valid entries in the MaskedTextBox, if I have no text entered when i execute:

        Me.DataBindings("Text").WriteValue()

(when ‘locking’ the MaskedTextBox) it then branches to the bound properties Get method as I step into each line of code in the debugger (as opposed to the Set method with other valid entries)

How can I write this null/nothing/”” value to the DateTime? property when no text “” is entered into the MaskedTextBox?

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:05:57+00:00Added an answer on May 14, 2026 at 10:05 pm

    In order to manipulate what value gets displayed in the bound control and saved in the bound property, you need to handle the Format and Parse events of the binding. See below a simplistic sample code:

    maskedTextBox1.DataBindings.Add("Text", bindobj, "Time");
    maskedTextBox1.DataBindings[0].Parse += new ConvertEventHandler(Form1_Parse);
    maskedTextBox1.DataBindings[0].Format += new ConvertEventHandler(Form1_Format);
    
    void Form1_Format(object sender, ConvertEventArgs e)
    {
        if (e.Value == null)
            e.Value = "Null";
    }
    private void Form1_Parse(object sender, ConvertEventArgs e)
    {
        DateTime d;
    
        if (DateTime.TryParse(e.Value.ToString(), out d))
            e.Value = d;
        else
            e.Value = null;
     }
    private void maskedTextBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
            maskedTextBox1.DataBindings[0].WriteValue();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.