Good afternoon.
Is there a way to format the UltraDateTimeEditor to only show a month/day within an Infragistics Grid? The user's don't want to see the year when choosing a range. For example: 01/01 to 12/31.
The value underneath can include the year but the visual month/day must not include the year. The code below works fine for my purposes for all dates until you test a leap year. The result is 12/29 and the grid / editor continues to throw errors for the invalid date since there is no year associated. Is there a way to supress the error or change the format as I have described above?
I have used this code to achieve the results:
string userDateFormat = GetUserDateFormat();string userDateFormatNoYear = userDateFormat.Replace("/yyyy", "");
// Start Daterow.Cells[START_DATE].Column.Format = "";uiDayMonthEditor.MaskInput = userDateFormatNoYear.ToLower();uiDayMonthEditor.FormatString = userDateFormatNoYear;row.Cells[START_DATE].EditorControl = uiDayMonthEditor;row.Cells[START_DATE].Column.UseEditorMaskSettings = true;
- Christopher
Hello Christopher,
this.ultraDateTimeEditor1.MaskInput = "mm/dd"; this.ultraDateTimeEditor1.FormatString = "mm/dd";
Please let me know if I misunderstood the problem.
Elizabeth AlbertLocalization Engineer
I was able to reproduce your issue. It seemed fine at first, but then when I added something else to the form so I could tab off, the value reverted. I discussed it with development and submitted a bug.
For workarounds, I tried to find out when the value reverted. It seems to happen before the Validating event fires, so I wasn't able to cancel it. Here are the things I tried... maybe it will help you find a workaround.
public Form1() { InitializeComponent(); this.ultraDateTimeEditor1.MaskInput = "mm/dd"; this.ultraDateTimeEditor1.FormatString = "MM/dd"; // This doesn't visibly affect the behavior //this.ultraDateTimeEditor1.InvalidTextBehavior = Infragistics.Win.UltraWinEditors.InvalidTextBehavior.PreserveWhileInEditMode; } // Trying to prevent the value from reverting when it is a leap year. // However, the value has already reverted before this event fires. private void ultraDateTimeEditor1_Validating(object sender, CancelEventArgs e) { DateTime val = ultraDateTimeEditor1.DateTime; if ((val.Day == 29) && ((val.Year % 4 == 0))) { e.Cancel = true; } } // The value has already reverted before the Leave event too. private void ultraDateTimeEditor1_Leave(object sender, EventArgs e) { DateTime val = ultraDateTimeEditor1.DateTime; MessageBox.Show(val.ToString()); }
I'm going to forward your post and the bug I submitted to Developer Support. They will be able to update you on the progress.
This issue has been submitted to development. A support case has been opened for you with reference number CAS-80592-169ZR6. You will receive updates through the support case.
The reply from the developer is that this functionality is not supported.
"The customer is trying to do something that the control does not support. There is no workaround because the year is not persisted independently of the mask. If you eliminate the year from the mask this control does not support the expected behavior."
When the year is not included in the mask, the editor assumes the current year. That means, if it is a leap year, then the value 02/29 will be accepted. I tried this out by changing my system date to January 2012, and then selecting 02/29 in the DateTimeEditor. It worked.
If only dates in the current year can be selected, then this will work for your requirements.
If dates outside of the current year can be selected, then I would recommend including the year in the MaskInput and FormatString.