none
Date TextBox Mask Missing the 0 in the month RRS feed

  • Question

  • I have a Textbox mask when I enter the data 02/22/2019 and save to the datagrid the grid shows the correct format but the textbox shows 22/22/019. What is the issue?


    Booney440

    Saturday, April 14, 2018 10:31 PM

Answers

All replies

  • Do you have the MaskedTextBox.FormatProvider Property set for any reason?

    Also have you checked the MaskFull or MaskCompleted properties MaskedTextBox Class?

    You don't show how the DataGridView is passed a value. Is it converted to a Date value before the DataGridView gets the value from the MaskedTextBox?

    Did you try using a Date mask MaskedTextBox.Mask Property?


    La vida loca

    Sunday, April 15, 2018 2:23 AM
  • The Access DatBase is set to date time, cant find an answer to why the leading 0 gets deleted.

    02/22/2019 = 22/22/019?


    Booney440

    Sunday, April 15, 2018 1:21 PM
  • I have also tried the code below but every time I start with a 0 it deletes it and pushes the other number over.

     private void Form1_Load_1(object sender, EventArgs e)
            {      
     maskedTextBox1.Mask = "00/00/0000";
    
                maskedTextBox1.MaskInputRejected += new MaskInputRejectedEventHandler(maskedTextBox1_MaskInputRejected);
                maskedTextBox1.KeyDown += new KeyEventHandler(maskedTextBox1_KeyDown);
            }
    
            void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
            {
                if (maskedTextBox1.MaskFull)
                {
                    toolTip1.ToolTipTitle = "Input Rejected - Too Much Data";
                    toolTip1.Show("You cannot enter any more data into the date field. Delete some characters in order to insert more data.", maskedTextBox1, 0, -20, 5000);
                }
                else if (e.Position == maskedTextBox1.Mask.Length)
                {
                    toolTip1.ToolTipTitle = "Input Rejected - End of Field";
                    toolTip1.Show("You cannot add extra characters to the end of this date field.", maskedTextBox1, 0, -20, 5000);
                }
                else
                {
                    toolTip1.ToolTipTitle = "Input Rejected";
                    toolTip1.Show("You can only add numeric characters (0-9) into this date field.", maskedTextBox1, 0, -20, 5000);
                }
            }


    Booney440

    Sunday, April 15, 2018 2:42 PM
    • Marked as answer by Booney440 Sunday, April 15, 2018 4:17 PM
    Sunday, April 15, 2018 4:05 PM
  • That worked.

    Thanks

    Go to Property of the masked text box. Select 'DataBindings', then 'Advanced'. Select 'Custom' in the 'Format Type' list box in the middle of the dialog box. Enter 'MM/dd/yyyy' in the 'Custom Format' box to the right.


    Booney440


    • Edited by Booney440 Sunday, April 15, 2018 4:57 PM update
    • Proposed as answer by VB amateur Wednesday, February 26, 2020 2:27 PM
    Sunday, April 15, 2018 4:18 PM
  • Maybe try setting the FormatProvider for the MaskedTextBox. Although I couldn't make the same issue occur so possibly it has something to do with binding it to a DataGridView or something or however you get the text from it.

    MaskedTextBox1.FormatProvider = New DateTimeFormatInfo


    La vida loca

    Sunday, April 15, 2018 4:23 PM
  • Thanks for the help. Works on using Visual Studio 2019 windows form app + Access 2007
    Wednesday, February 26, 2020 2:28 PM