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
170
Custom Column style on XamDataGrid in code
posted

I am new to this system... am trying to set the format of a couple DateTime columns in my XamDataGrid to use a format like "dd/mm/yyyy hh:mm:ss", and I need to do it in code it seems, as my grid has a DataSource, and if I try anything in Xaml I get an error.

I got as far as creating a style, as in

			Style mystyle = new Style(typeof(XamMaskedEditor) ;

I am unsure about how to add a setter to specify the desired format ... and then apply that to the columns in question (which are the only columns of type DateTime).

I guess this is pretty basic... but as I novice, I've already spent many hours trying to figure it out... time to ask for help ;-)

Any pointers appreciated.

  • 7535
    Verified Answer
    Offline posted

    Hello Trevor,

    The grid assumes default date formatting, or the formatting of the default / current culture. To override that, just create a style that targets the xamTextEditor of the field and set its Format dependency property to the date format you need. Like this:

    Style st = new Style(typeof(XamTextEditor));
    Setter setter = new Setter(XamTextEditor.FormatProperty, "dd MMM yyyy hh:mm:ss");
    st.Setters.Add(setter);
    

    and then you can apply this style to your datetime type, say you have a datetime field called ModifiedDate, then you can do the following.

    dataGrid1.Records.FieldLayout.Fields["ModifiedDate"].Settings.EditorStyle = st;

    Hope this will help.