C1FlexGrid UTC DateTime to Local

Posted by: scadavantagesupport on 9 March 2018, 8:51 am EST

    • Post Options:
    • Link

    Posted 9 March 2018, 8:51 am EST

    Hi,

    I am using C1FlexGrid and I have a read-only data bound column that contains a UTC date time. I want to display that date time in local time. Do you have an example of a way to do that?

  • Posted 12 March 2018, 12:12 am EST

    Hello,

    Would it be possible for you to convert datetime to LocalTime using .ToLocalTime() method in the get accessor of the property itself(to which you are binding the datetime column) . This seems to work in attached sample application.

    Let me know, if I am missing anything here.

    Thanks,

    Ruchir Agarwal

    C1FlexGrid_LocalTime.zip

  • Posted 12 March 2018, 3:37 am EST

    No, that would not be ideal. I want to be able to have two columns, one showing UTC time the other showing local time. The object I am dealing with is a database entity and only has one timestamp field. I cannot modify the source object. My only other option would be to write a wrapper but that is a lot of overhead I was hoping to avoid.

  • Posted 13 March 2018, 12:11 am EST

    Hi,

    In that case, you may create a Class inheriting from CellFactory and override its CreateCellContent method and translate the value there, as follows:```

    public class MyCellFactory : CellFactory

    {

    public override void CreateCellContent(C1FlexGrid grid, System.Windows.Controls.Border bdr, CellRange rng)

    {

    if(grid.Columns[rng.Column].ColumnName == “LocalTime”)

    {

    var date = Convert.ToDateTime(grid.Cells[rng.Row, rng.Column]).ToLocalTime();

    TextBlock tb = new TextBlock();

    tb.Text = date.ToString();

    bdr.Child = tb;

    }

    else

    {

    base.CreateCellContent(grid, bdr, rng);

    }

    }

    public override void DisposeCell(C1.WPF.FlexGrid.C1FlexGrid grid, C1.WPF.FlexGrid.CellType cellType, System.Windows.FrameworkElement cell)

    {

    Border bdr = (Border)cell;

    bdr.Child = null;

    }

    }

    I have modified attached sample application, implementing the above, for your reference.
    
    Let me know, if you have any issues.
    
    Regards,
    Ruchir Agarwal
    [zip filename="C1FlexGrid_LocalTimeCellFactory.zip"]public\uploads\cfa478abb6df64feacd923999508d55c1520946666451.zip[/zip]
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels