Hey guys, I've inherited RadDateTimePicker to do a better handling of null value with databinding and the problem is when it got focused by Tab key it borders don't change as it should be. Ive tried setting focus to DateTimePickerElement when my picker got focus, but it didn't solve as well.
public partial class NossoRadDateTimePicker : RadDateTimePicker
{
public NossoRadDateTimePicker()
{
InitializeComponent();
TabStop = true;
this.ValueChanged += NossoRadDateTimePicker_ValueChanged;
this.GotFocus += NossoRadDateTimePicker_GotFocus;
}
private void NossoRadDateTimePicker_GotFocus(object sender, EventArgs e)
{
base.DateTimePickerElement.Focus();
}
private void NossoRadDateTimePicker_ValueChanged(object sender, EventArgs e)
{
if (ShowCheckBox && checking == false)
this.Checked = true;
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new DateTime? NullableValue
{
get
{
throw new Exception("Use Value");
}
set
{
throw new Exception("Use Value");
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
/// <summary>
/// Poderá retornar null caso use o checkbox e ele não esteja checkado
/// </summary>
public new DateTime? Value
{
get
{
DateTime? valor = base.Value;
if (ShowCheckBox && Checked == false)
valor = null;
return valor;
}
set
{
//garantir que essa bosta n sete valor fora do range de datas
if (value != null)
{
value = value > MaxDate ? MaxDate : value;
value = value < MinDate ? MinDate : value;
Checked = true;
}
else if (ShowCheckBox)
Checked = false;
checking = true;
base.Value = value ?? DateTime.Now;
checking = false;
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyData == Keys.Space)
{
this.Checked = !this.Checked;
}
else
{
base.OnKeyDown(e);
}
}
bool checking;
}