Home Forums WPF controls Xceed DataGrid for WPF DateTime formatting

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

    Hi,

    I have a DateTime column in the grid – how can I format this (in my case seconds have to be displayed too)?

    Thanks!

    Imported from legacy forums. Posted by Ludwig (had 576 views)

    User (Old forums)
    Member
    Post count: 23064

    You could use a IValueConvertor as show in the Xceed documentation – Formatting a cell’s content

    or the DateTimeTextBox which takes in a DateTimeMaskMode or a custom specified mask.

    This is what I did to get a datetime textbox cell editor

    /// <summary>
    /// Method to get a Date Time Textbox cell editor
    /// </summary>
    /// <returns></returns>
    static public DataTemplate CellEditorDateTimeTxtDataTemplate(DateTimeMaskMode dateTimeMaskMode)
    {
                FrameworkElementFactory DateTimeEditor = new FrameworkElementFactory(typeof(DateTimeTextBox));

                Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension myCellEditorBinding = new Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension();

                DateTimeEditor.SetValue(DateTimeTextBox.DateTimeMaskModeProperty, dateTimeMaskMode);

                DateTimeEditor.SetBinding(DateTimeTextBox.TextProperty, (BindingBase)myCellEditorBinding.ProvideValue(null));
                DataTemplate template = new DataTemplate(typeof(DateTimeTextBox));
                template.VisualTree = DateTimeEditor;

                return template;
    }

    Hope that helped!

    Cheerios,

    Serene 

     

    Imported from legacy forums. Posted by Serene (had 1585 views)

    User (Old forums)
    Member
    Post count: 23064

    I tried this:

                    foreach (Xceed.Wpf.DataGrid.Column column in grid.Columns)
                    {
                        string title = (string)column.Title;
                        if ((title == “Starts”)
                            || (title == “Ends”))
                        {
                            column.CellContentTemplate = CellEditorDateTimeTxtDataTemplate(DateTimeMaskMode.ShortDateAndShortTime);
                        }
                    }

    And it does show the right format but no data is displayed even though the data is there in the bound DataTable. 

     

    Imported from legacy forums. Posted by s (had 1166 views)

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