Community-Credit.com | NonProfitWays.com | SOAPitstop.com   Skin:   
      User: Not logged in 
Home
Newsletter Signup
XSLT Library
Latest XML Blogs
Featured Examples
Presentations
Featured Articles
Book Chapters
Training Courses
Events
NewsGroups
 
Discussions
Examples
Tutorials
Tools
Articles
Resources
Websites
 
Sign In
My Profile
My Articles
My Examples
My Favorites
My Resources
Add a Resource
Logout
 
About Me
My Blog
HeadGeek Articles
Talking Portfolio
Resume
Pictures
World Trip Pics

Winforms DateTime picker with NULL binding support
Author: Duray AKAR
Published: 3/17/2006 12:09 PM
Category: ADO.NET, C#
Summary: The winforms datetimepicker control does not support null binding by default. so I had to create my own

 

Here is an example of a bindable DateTimePicker with NULL binding support.

It is just a fw lines of code, so no need to download... Just copy and paste. ;)

Hope it helps

 

Duray AKAR

 

    public class DateTimePickerNullable: System.Windows.Forms.DateTimePicker, INotifyPropertyChanged
    {
        public DateTimePickerNullable()
            : base()
        {
            ShowCheckBox = true;
        }

        [Bindable(true)]
        public Nullable<DateTime> BindableValue
        {
            get
            {
                if (Checked)
                {
                    return Value;
                }
                else
                {
                    return null;
                }
            }
            set
            {
                if (value.HasValue && value.Value > DateTime.MinValue)
                {
                    this.Checked = true;
                }
                else
                {
                    this.Checked = false;
                }
            }
        }

        public new bool Checked
        {
            get { return base.Checked; }
            set
            {
                base.Checked = value;
                OnPropertyChanged("BindableValue");
            }
        }

        protected override void OnCloseUp(EventArgs eventargs)
        {
            base.OnCloseUp(eventargs);
            OnPropertyChanged("BindableValue");
        }


        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged!=null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
            }
        }

        #endregion
    }


 

 
Fans of "The Office"
Dwight Bobbleheads are here!
  “It's me! I'm the bobblehead! Yes!”



Advertise on XMLPitstop

Advertise on XMLPitstop


EggHead Cafe
Web Servicee development
DotNetSlackers
Buy text ads here!
Color Laser Printer
online business degree
designer sunglasses
Skype vs. sipcall
VoIP Internettelefonie
Buy text ads here!

Interested in Text ads?
2,219 Total Members
34 members(last 30 days)
7 members(last 7 days)
1 members(today)

1,609 Total Discussions
14 Posts(last 30 days)
0 Posts(last 7 days)
0 Posts(today)

17,106 Total Blog Posts
1,791 Blogs(last 30 days)
273 Blogs(last 7 days)
44 Blogs(today)

8,699 Newsgroup Posts
0 Posts(last 30 days)
0 Posts(last 7 days)
0 Posts(today)

13,785 Total Resources
4 Resources(last 30 days)
1 Resources(last 7 days)
0 Resources(today)


 

David Silverlight's XMLPitstop.com| 2801 Florida Ave #225|Miami, FL 33133|Ph:305-447-1139