Forum  General Visual ...  How do I...?  Optional DatePicker and Money Controls
Previous Previous
 
Next Next
New Post 9/13/2008 7:44 PM
  rdhatch
635 posts
1st Level Poster




Re: Optional DatePicker and Money Controls 
Nullable Date Picker:  Eyal - Please let us know when the Nullable Date Picker is ready!!
Ryan D. Hatch, VWG MVP
GeniusCode.net | VWG Community Frameworks | VWG Wiki
 
New Post 9/14/2008 5:11 AM
  Eyal.Albert
393 posts
3rd Level Poster




Re: Optional DatePicker and Money Controls 
Hi,
I think that there was a miss understanding.
We are not working on making the DateTimePicker null able.
VWG is imitating WinForms and in WinForms the DateTimeOPicker can’t accept a null value.
If you need a DateTimePicker that accepts null you will have to create a custom control of your own.
I would love to help you with it.
Please let me know what you need.
Eyal Albert
 
New Post 9/15/2008 7:04 PM
  rrichins
24 posts
No Ranking


Re: Optional DatePicker and Money Controls 
This is what I use.


namespace ControlLibrary
{
public partial class DatePicker : BaseControl
{
public String _Heading
{
get
{
return label1.Text;
}
set
{
label1.Text = (value ?? string.Empty).ToString();
}
}
public String _Text { get; set; }
public Boolean _Queued { get; set; }
public Gizmox.WebGUI.Forms.DateTimePicker dateTimePicker1 { get; set; }


public DatePicker()
{
InitializeComponent();
_Queued = true;
}

void splitContainer1_Resize(object sender, EventArgs e)
{
splitContainer1.SplitterDistance = (splitContainer1.Size.Width / 2) - 1;
splitContainer1.Panel1.Update();
splitContainer1.Panel2.Update();
}
public override BaseControl Initialize(BaseControl Parent)
{
base.BaseInitialize(Parent, this);
splitContainer1.SplitterDistance = (splitContainer1.Size.Width / 2) - 1;
splitContainer1.Panel1.Update();
splitContainer1.Panel2.Update();
splitContainer1.Resize += new EventHandler(splitContainer1_Resize);
if (_ColumnValue == null)
_ColumnValue = Null.NullDate;
if ((DateTime)_ColumnValue != null
&& (DateTime)_ColumnValue > Null.NullDate)
{
this.splitContainer1.Panel2.Controls.Clear();
dateTimePicker1 = new DateTimePicker();
dateTimePicker1.Size = textBox1.Size;
dateTimePicker1.Dock = DockStyle.Fill;
dateTimePicker1.Value = (DateTime)_ColumnValue;
dateTimePicker1.Format = DateTimePickerFormat.Short;
if (_Queued)
dateTimePicker1.ValueChangedQueued += new EventHandler(dp_ValueChangedQueued);
else
dateTimePicker1.ValueChanged += new EventHandler(dp_ValueChanged);
_Text = dateTimePicker1.Value.ToShortDateString();
splitContainer1.Panel2.Controls.Add(dateTimePicker1);
}
else
{
textBox1.Click += new EventHandler(textBox1_Click);
textBox1.TextChanged +=new EventHandler(textBox1_TextChanged);
}
return this;
}

void textBox1_TextChanged(object sender, EventArgs e)
{
if (dateTimePicker1 == null)
{
_ColumnValue = DateTime.Now;
this.splitContainer1.Panel2.Controls.Clear();
dateTimePicker1 = new DateTimePicker();
dateTimePicker1.Size = textBox1.Size;
dateTimePicker1.Dock = DockStyle.Fill;
dateTimePicker1.Value = (DateTime)_ColumnValue;
dateTimePicker1.Format = DateTimePickerFormat.Short;
if (_Queued)
dateTimePicker1.ValueChangedQueued += new EventHandler(dp_ValueChangedQueued);
else
dateTimePicker1.ValueChanged += new EventHandler(dp_ValueChanged);
splitContainer1.Panel2.Controls.Add(dateTimePicker1);
_Text = dateTimePicker1.Value.ToShortDateString();
Text = DateTime.Now.ToLongTimeString();
}
}

void textBox1_Click(object sender, EventArgs e)
{
if (dateTimePicker1 == null)
{
_ColumnValue = DateTime.Now;
this.splitContainer1.Panel2.Controls.Clear();
dateTimePicker1 = new DateTimePicker();
dateTimePicker1.Size = textBox1.Size;
dateTimePicker1.Dock = DockStyle.Fill;
dateTimePicker1.Value = (DateTime)_ColumnValue;
dateTimePicker1.Format = DateTimePickerFormat.Short;
if (_Queued)
dateTimePicker1.ValueChangedQueued += new EventHandler(dp_ValueChangedQueued);
else
dateTimePicker1.ValueChanged += new EventHandler(dp_ValueChanged);
splitContainer1.Panel2.Controls.Add(dateTimePicker1);
_Text = dateTimePicker1.Value.ToShortDateString();
Text = DateTime.Now.ToLongTimeString();
}
}

void dp_ValueChanged(object sender, EventArgs e)
{
try
{
_ColumnValue = dateTimePicker1.Value;
_Text = dateTimePicker1.Value.ToShortDateString();
Text = DateTime.Now.ToLongTimeString();
}
catch { }
}

void dp_ValueChangedQueued(object sender, EventArgs e)
{
try
{
_ColumnValue = dateTimePicker1.Value;
_Text = dateTimePicker1.Value.ToShortDateString();
Text = DateTime.Now.ToLongTimeString();
}
catch { }
}
}
}

You'll have to strip out the basecontrol stuff, but if the _ColumnValue is null an empty textbox is displayed, as soon as the user clicks in the textbox it is replaced with a datetime picker set to the current date.

Hope this helps,

Ron
 
Previous Previous
 
Next Next
  Forum  General Visual ...  How do I...?  Optional DatePicker and Money Controls
CompanionKit Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS