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
785
IGGridView'DateTime'ColumnDefinition
posted

Hey - Frist, I'd like to thank you for your answers to my previous posts. They have all been spot on and the grid is working great for the application were building, in fact it's crucial.

 

My next question relates to binding to a DateTime object:

[Export("DateOfService")]

public DateTime DateOfService {get; set;}

 

If I use just a regular IGGridViewColumnDefinition it does not render the value properly in the grid. I suspect I'm going to need to create my own class that inherits the IGGridViewColumnDefinition similar to how the Netflix example works in one of your blogs. Is that the proper approach at this time or is there a better way to accomplish this?

 

Using C#

Parents
No Data
Reply
  • 40030
    Verified Answer
    Offline posted

    Hi!, 

    So when I tried to use DateTime for my property it just crashes. Instead, I believe you should be using NSDate. The nice thing about that, is it actually accepts DateTime values, for example:

    [Export("date")]
    public NSDate Date{get;set;}

    obj.Date = DateTime.Now.Add (TimeSpan.FromDays(i));

    Now that would allow it to display date. However that date won't be properly formatted. For that your best option would be to create a custom column. That way you can display the date however you'd like in a cell. 

    public class DateColumn :IGGridViewColumnDefinition
        {
            string _fieldKey;

            public DateColumn(string key):base()
            {
                _fieldKey = key;
            }

            public override string FieldKey 
            {
                get 
                {
                    return _fieldKey;
                }
            }
        
            public override IGGridViewCell CreateCell (IGGridView gridView, IGCellPath path, IGGridViewDataSourceHelper dataSource)
            {
                IGGridViewCell cell = (IGGridViewCell)gridView.DequeueReusableCell("dateCell");
                if(cell == null)
                {
                    cell = new IGGridViewCell ("dateCell");
                
                }

                DummyData e = (DummyData)dataSource.ResolveDataObjectForRow(path);
                DateTime dt = e.Date;
                cell.TextLabel.Text = dt.ToShortDateString ();

                return cell;
            }
        }


    DateColumn col1 = new DateColumn ("date");
     _dsh.ColumnDefinitions.Add(col1);

    Hope this helps, 

    -SteveZ

Children
No Data