Approved
Last Updated: 22 Oct 2019 08:16 by ADMIN
Tomislav
Created on: 21 Oct 2019 07:50
Category: UI for WinForms
Type: Feature Request
0
RadDateTimePicker - MaskDateTimeProvider - Enable setting more days in a month than the month has(max 31) but set the month to the next

I would like to request 2 features/properties:

  1. Disable going back to the days on year editing end (hacked here by the SelectFirstItem() override).
  2. Enable inserting number of days that is currently more than the allowed days in the month by adding one month (hacked by the HandleKeyPressDay() override and MyDayLogic())
    • the date set is 15.09.2019, we start writing the date 31.12.2019. Currently you have to change the months first than the days
    • i guess this is a problem for formats with days first but it is a problem

 

public class MyMaskDateTimeProvider : MaskDateTimeProvider
{
public MyMaskDateTimeProvider(string mask, CultureInfo culture, RadMaskedEditBoxElement owner)
: base(mask, culture, owner)
{
this.AutoSelectNextPart = true;
}

public override void SelectFirstItem() { } //base.SelectFirstItem(); //we do not want to go back to the days after the year part

protected override void HandleKeyPressDay(MaskPart part, KeyPressEventArgs e)
{
if(!int.TryParse(e.KeyChar.ToString(), out int result))
return;
string str = part.value.ToString();
int num1 = 0;
int num2;
if(part.hasZero)
{
if(num1 < part.min
|| num1 > part.max)
{
num2 = result;
}
else
{
if(str.Length > 1)
str = str.Substring(1);
num2 = int.Parse(str + e.KeyChar);
}
}
else
{
if(str.Length > 1)
str = str.Substring(1);
num2 = int.Parse(str + e.KeyChar);
}

if(part.day)
{
MyDayLogic(part, num2, result);
}
else
{
part.value = num2 < part.min || num2 > part.max
? result
: num2;
}

part.hasZero = result == 0;
}

private void MyDayLogic(MaskPart part, int num2, int result)
{
//logic for not continuing when changing days and current set month has less days then days needed, when that happens add one month to the current
if((num2 < part.min)
|| (num2 > part.max))
{
if((num2 > part.min)
&& (num2 <= 31))
{
SelectNextEditableItem();
Up(this.List[this.SelectedItemIndex], this.MinDate, this.MaxDate);
SelectPrevEditableItem();
SelectNextEditableItem();
part.value = num2;
}
else
{
part.value = result;
}
}
else
{
part.value = num2;
}
}
}

1 comment
ADMIN
Dimitar
Posted on: 22 Oct 2019 08:16

Hello Tomislav,

I have approved your request and updated your Telerik Points.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.