如何允许DateTimePicker为空? [英] How allow DateTimePicker to be empty?
问题描述
我正在制作WinForms应用程序。使用EF 6从Database First设计创建EDM。此生产数据库已存在,Azure SQL DB。它是一个包含100个表和100个用户的大型数据库,但使用MS Office Access作为前端。我正在尝试将
慢慢地将一些功能移植到C#WinForms作为系统管理员,因为我学习了如何为用户自己设计前端应用程序。
我创建了一个表单来编辑用户。我发现数据库用户使用EF并通过表单的构造函数将其传递给EditUser表单。然后当表单加载时,我将每个TextBox / ComboBox值设置为我从EF上下文得到的对象的值。
我遇到的问题是我将DateTimePicker用于Nullable的某些日期。如果需要,我希望选项有空日期。但我无法弄清楚如何使用DateTimePicker并能够将日期留空。
感谢您的建议!
I'm making a WinForms application. Using EF 6 to create an EDM from a Database First design. This production database already exists, Azure SQL DB. Its a big database with 100 tables and 100 users, but uses MS Office Access as a front end. I'm trying to
slowly port some functionality to C# WinForms for myself as the system admin as I learn how to design a front end application for the users themselves.
I've created a Form to edit the users. I find the DB User using EF and pass and instance of it to an EditUser form via the form's constructor. Then when the form loads I set each TextBox/ComboBox value = to the value from the object I got from the EF Context.
The issue I run into is that I use DateTimePicker for some dates that are Nullable. I want the option to have empty dates if I need to. But I can't figure out how to use a DateTimePicker and have the ability to leave a date empty.
Thanks for the advice!
推荐答案
您好HTHP,
Hi HTHP,
>>但我无法弄清楚如何使用DateTimePicker和能够将日期留空。
>>But I can't figure out how to use a DateTimePicker and have the ability to leave a date empty.
请使用以下代码:
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = " ";
希望有所帮助!
最好的问候,
Stanly
这篇关于如何允许DateTimePicker为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!