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.
Hello Michael,
Thank you for your feedback. I am glad that I helped you to resolve your issue and I believe that other community members may benefit from this as well.
Thanks again.
Hi Stefan,
As far as I can see that seems to do the trick.
Thanks for the quick and clear response.
Regards
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.