Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
185
UltraCalendarCombo doesn't retain focus on ValidationError
posted

Hello,

I've been following this post:
http://www.infragistics.com/community/forums/p/29234/171938.aspx#171938
but seems unresolved.

I'm using a custom control that inherits from UltraCalendarCombo. When the user types an invalid date text, I would like the control retains the focus with the invalid text instead of the last valid value with an error message through an error provider component.

I've achieved to show an error message in the control and retain the focus. However, I cannot retain the invalid text and set the control in edit mode.

The problem for me is to cancel the Leave (OnLeave) or LostFocus (OnLostFocus) events.

I've tried something like this:

  protected override void OnEnter(EventArgs e)
  {
      // Invalid is set to true in OnValidationError and
      // OnLostFocus when the text cannot be parsed to a DateTime
      if (!this.Invalid)
      {
                this.Appearance.BorderColor = SequelUltraStyle.ColorFocusedBorder;
                base.OnEnter(e);               
      }
      else
      {
                // Keep the focus but not in edit mode.
                this.SetFocus();
      }
      this.Invalid = false;
  }

  protected override void OnLeave(EventArgs e)
  {
            // Invalid is set to true in OnValidationError and
            // OnLostFocus when the text cannot be parsed to a DateTime
            if (!this.Invalid)
            {
                  this.Appearance.ResetBorderColor();
                  base.OnLeave(e);
            }
            else
            {
                 // Keep the focus but not in edit mode
                 this.SetFocus();
            }
  }

Is there any workaround to get what I want?

P.D. I'm using Infragistics2.Win.UltraWinSchedule.v10.3

Thanks!

Oscar

Parents
  • 469350
    Offline posted

    Hi Oscar,

    Is the error text a valid date that is invalid for other reasons? Or is the text itself invalid for a date?

    If it's the former, than I think you can use the ValidationError event and set e.NewValue = e.ErrorValue to maintain the bad value. But e.NewValue has to be a DateTime. So this won't work if the value is not a valid date.

Reply Children
No Data