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
475
Setting default value for the XamDateTimeEditor’s dropdown XamMonthCalendar when first cell in a new row
posted

Hi,

 

I have a grid that looks like the following…

The first field in the underlying data row object is a DateTime using the following XAML.

 

<igDP:Field Name="RowDateTime">

       <igDP:Field.Settings>

              <igDP:FieldSettings EditAsType="{x:Type sys:DateTime}">

                     <igDP:FieldSettings.EditorStyle>

                           <Style TargetType="{x:Type igEditors:XamDateTimeEditor}">

                                  <Setter Property="Mask" Value="{}{date} {time}" />

                           </Style>

                     </igDP:FieldSettings.EditorStyle>

              </igDP:FieldSettings>

       </igDP:Field.Settings>

</igDP:Field>

 

I want the user to be able to add new rows by just editing in the add row area.  Initially on the new row the date time is empty and if they hit the dropdown button it defaults to today’s date.  But what I need is for the new date time to default to 1 hour after the current latest time in the grid ie. In above case I want 01/01/2004 01:00 plus one hour ie. 01/01/20004 02:00. 

 

However, no where can I see how to do this for the XamDataGrid.    The RecordAdding event occurs after the user tabs away from (finishing editing) the date field.  The InitializeTemplateAddRecord event initializes the field before any edit takes place.

 

The date field has to be the first one – I don’t have the option to move it as we are updating from an old C++ grid and have to maintain compatability.

 

Please can you advise how to do this.  As usual very, very difficult to configure trivial things in the XamDataGrid.  Makes the 10 year old Objective Grid seem like quality.

 

 

 

Parents
  • 138253
    Verified Answer
    Offline posted

    Hello Michael,

    Thank you for your post. I have been looking through it and I suggest you add an EventSetter for the DropDownOpened event to the XamDateEditor’s Style with EventHandler called MyDropDownOpened e.g. and add the following code into it:

    if ((Utilities.GetAncestorFromType(sender as XamDateTimeEditor,typeof(DataRecordPresenter),true) as DataRecordPresenter).IsAddRecord)
    {
        DateTime max = new DateTime();
        foreach (var item in xamDataGrid1.Records)
    	{
            if (max.CompareTo((item as DataRecord).Cells[0].Value ) == -1)
    	    {
    		    max = (DateTime)(item as DataRecord).Cells[0].Value;                    
    	    }
        }
        (sender as XamDateTimeEditor).Value = max.AddHours(1);
    } 
    

     

    Please let me know if this is what you are trying to achieve or I have misunderstood you in some way.

    Looking forward for your reply.

Reply Children
No Data