本文介绍了掩码文本框不保存月份的前导0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我输入数据02/22/2019时,我有一个文本框掩码并保存到数据网格,网格显示正确的格式,但掩码文本框显示22/22/019。它正在删除前导数据0.数据源是Access数据库,它设置为日期时间。有什么问题?我也在代码中尝试了它但仍然得到了相同的结果。



结果保存在网格和数据库中= 02/22/2019

当我选择网格行时,它在掩码文本框中显示为22/22/019,错过了0.



任何帮助



我尝试了什么:



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 mask textbox shows 22/22/019. It's deleting the leading 0. Data source is Access database and it is set to date time. What is the issue? I have also tried it in code but still get the same results.

Results saved in Grid and database = 02/22/2019
When I select the grid row it shows in the mask textbox as 22/22/019, missing the 0.

Any help

What I have tried:

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);
            }
        }

推荐答案


这篇关于掩码文本框不保存月份的前导0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 06:27
查看更多