Is there a way to default the date to today's date and remove the time (in red) in the add row section of the grid.
Hello mmalsor,
I have been looking into your enquiry and usually the default values in the AddNewRow come from the data object class’s default constructor, however by only setting the ItemsSource to my XamGrid I get a different result, which seems to be what you are looking for:
I suppose you have done some modifications that are causing this.
Please let me know if you require any further assistance on the matter.
Hi Petar,
Thanks for looking into this. I am binding the grid to an observable collection. The grid loads fine with the date. The one I like to default is the add row section of the grid. When it is clicked and is enabled for entry it defaults the date to an invalid date. I would like to default that to todays date.
Hello Petar,
Sorry for the late response.
I could not get your solution to work. My data is coming from entity framework 4 and not sure how I can have it default the date like you have.
Hello Marie,
I have been looking into your requirement, however I was not able to find another suggested approach for doing that. This is why I can suggest you learn how to override your constructor, or perhaps create a wrapper class in which you can do that. Besides from that I can create a Feature Request on your behalf so a more straight forward approach is provided by the XamGrid in one of our future releases.
Please let me know if I can be of any further assistance.
Thanks Petar! I'll just override the constructor.
Hi,
The XamGrid exposes the DataObjectRequested event, which is raised when there's a necessity for a new object to be created (which is the case when you use the AddNewRow). This event is useful for cases when your underlying data objects do not have a default constructor (so the grid would not be able to create them on its own), or you want to set specific property values on these objects (as in your case - set the date to 'Today').
To eliminate the "Time" part in the Editor, you can use a TemplateColumn and set a StringFormat on the EditorTemplate.
Attached is a sample that demonstrates both approaches.
Hope this helps,
Thanks Georgi! Exactly what I'm looking for!