Home Forums WinForms controls Other WinForms controls WinDatePicker’s NullDateString

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #18549 |

    I have set the NullDateString to empty but somehow when I am showing the form where the control (WinDatePicker) is located it is still showing (null), I would want to be empty instead of (null). I somehow noticed that it only gets empty when I have focused and remove the focus on the control.

    Is there a way that I could automatically set it to empty when the form is displayed?

    Thank you so much

    Imported from legacy forums. Posted by Rodelio (had 4658 views)

    User (Old forums)
    Member
    Post count: 23064

    We do not reproduce this on our side.  When we set NullDateString to empty, it works fine.

    e.g.:

          winDatePicker1.NullDateString = string.Empty;

    If you have a code snippet that reproduce this, supply it so we can investigate it further.

    Imported from legacy forums. Posted by André (had 2280 views)

    User (Old forums)
    Member
    Post count: 23064

    I have already tried setting it when in the form’s load event and also by just deleting the default “(null)” in the properties window to no avail. Is there any other setting that could affect the NullDateString?

    And also, what is the surefire way of testing if the WinDatePickers date is a null? For now I am testing it against the NullDate like the following:

    if (date1.Value != date1.NullDate)
      testClass.Date1 = date1.Value;
    else
      testClass.Date1 = null;

    Is there a more elegant way to perform the validation against a null date?

    TIA

    Imported from legacy forums. Posted by Rodelio (had 2353 views)

    User (Old forums)
    Member
    Post count: 23064

    There is no setting that affect the NullDateString.

    The only thing I can think of is that there is an exception, which is swallowed by the grid or the framework which you don’t see.  Is your debugger set to break on all exceptions? (Debug Menu -> Exceptions -> Common Language Runtime Exception, then select “Break into the debugger” radio button in VS2003, or select “Thrown” CheckBox in VS2005).

    If you are in VS2005, make sure the “Enable Just My Code” CheckBox is unselected (Tools Menu -> Options -> Debugging -> General).

    For the null data verification, what you are doing is fine.

     

    Imported from legacy forums. Posted by André (had 588 views)

    User (Old forums)
    Member
    Post count: 23064

    Tried your suggestion but still there is no exception being caught. But in my attempt to automate the replacement of all my usercontrols with Xceed.Editors.WinDatePicker I accidentally found a solution which works on my case. Disregarding all the other initializations created by VS when one drops a WinDatePicker into a form, I instead just used the following properties and it worked as I want it to be.

    this.dateL1.Enabled = false;
    this.dateL1.Location = new System.Drawing.Point(186, 285);
    this.dateL1.Name = “dateL1”;
    this.dateL1.Size = new System.Drawing.Size(136, 21);
    this.dateL1.TabIndex = 104;
    this.dateL1.ForeColor = System.Drawing.Color.Navy;
    this.dateL1.NullDateString = “”;
    this.dateL1.DropDownControl.SelectedDate = new System.DateTime(((long)(0)));

    I really appreciate your responses, thanks a lot.

    Imported from legacy forums. Posted by Rodelio (had 2245 views)

    User (Old forums)
    Member
    Post count: 23064

    Another solution which works is to just inherit the WinDatePicker and modify the behaviour, as such I will not need to change my treament of the Value which is not a nullable DateTime.

    public partial class CustomDateTimePicker : Xceed.Editors.WinDatePicker
    {
      private DateTime? dtNullable;

      public CustomDateTimePicker()
      {
      base.NullDateString = string.Empty;
      base.Value = base.NullDate;
      InitializeComponent();
      }

      public new DateTime? Value
      {
      get
      {
      if (dtNullable.HasValue)
      return base.Value;
      return null;
      }
      set
      {
      if (value == null)
      {
      dtNullable = null;
      base.Value = base.NullDate;
      }
      else
      {
      if (value == base.NullDate)
      {
      dtNullable = null;
      base.Value = base.NullDate;
      }
      else
      {
      dtNullable = value.Value;
      base.Value = value.Value;
      }
      }
      OnValueChanged(EventArgs.Empty);
      }
      }

      protected override void OnValueChanged(EventArgs eventargs)
      {
      if (!this.dtNullable.HasValue)
      base.Value = base.NullDate;

      base.OnValueChanged(eventargs);
      }

    Imported from legacy forums. Posted by Rodelio (had 4825 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.