Hi Expert,
I have developing a window application with datepicker as (UI component).
In this, i select the date and update means it does not insert into db. But select in the second time it gets updated in db.
First time it retrieve null values only
second time retrieve the date and gets updated in db
Please help me out on this.
UI Componenet
using System;
using System.Windows.Forms;
namespace UIComponent
{
/// <summary>
/// Summary description for DateTimePicker.
/// </summary>
public class DateTimePicker : System.Windows.Forms.DateTimePicker
{
private DateTimePickerFormat oldFormat = DateTimePickerFormat.Long;
private string oldCustomFormat = null;
private bool bIsNull = false;
public DateTimePicker()
: base()
{
}
public new DateTime Value
{
get
{
if (bIsNull)
return this.MinDate;
else
return base.Value;
}
set
{
if (value == this.MinDate)
{
if (bIsNull == false)
{
oldFormat = this.Format;
oldCustomFormat = this.CustomFormat;
bIsNull = true;
}
this.Format = DateTimePickerFormat.Custom;
this.CustomFormat = " ";
}
else
{
if (bIsNull)
{
this.Format = oldFormat;
this.CustomFormat = oldCustomFormat;
bIsNull = false;
}
base.Value = value;
}
}
}
public void SetToNullValue()
{
Value = this.MinDate;
}
protected override void OnCloseUp(EventArgs eventargs)
{
if (Control.MouseButtons == MouseButtons.None)
{
if (bIsNull)
{
this.Format = oldFormat;
this.CustomFormat = oldCustomFormat;
bIsNull = false;
}
}
base.OnCloseUp(eventargs);
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.KeyCode == Keys.Delete)
this.Value = this.MinDate;
}
}
}
Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/