SmartDate and Custom User ControlSmartDate and Custom User Control
Old forum URL: forums.lhotka.net/forums/t/2287.aspx
Ronbo posted on Tuesday, February 06, 2007
I did a search and could not find anything along these lines. I have created a custom user control which consists of a masked edit control and a Windows DatePicker. The masked edit allows manual input from the user and the datepicker allows them to choose a date and pushes it into the masked edit control. They can only see the drop down button on the date picker, not the value portion. My problem is that I have to bind to an object type because they can enter a partial value such as 12/24/____. If I was binding to a smart date that would blow up, so I must use an object or string type. So I tried binding to SmartDate.DBValue and the control functions perfect, except when I lose focus and the property should go to the setter, it bypasses the property setter and goes directly to the private smartDate variable, thus bypassing my business rules. I understand its not the best explanation but I can send code snippets if it will help. Any help would be great, thanks.Brian Criswell replied on Tuesday, February 06, 2007
First off, regardless of what you use, wrap the use of _smartDate.xyz in a property. The most common pattern for using SmartDate is
public string MyDate
{
get
{
CanReadProperty("MyDate", true);
return _myDate.Text;
}
set
{
CanWriteProperty("MyDate", true);
if (!_myDate.Equals(value))
{
_myDate.Text = value;
PropertyHasChanged("MyDate");
}
}
}
This keeps it from bypassing your business rules. You may want to just try using a text box bound to a string property on your object and see what happens when the user types in "12/24". Don't for get to use a bindingsourcerefresh component.
Copyright (c) Marimer LLC