Forum Xamarin.Mac


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Implementing editable optional Date cell in NSTableView

rrradorrrado Member ✭✭

I need to show and edit date in the cell. In NSTableViewDelegate.GetViewForItem I create view like this:

view = new NSTextField();
view.Editable = true;
view.Formatter = new NSDateFormatter
       DateStyle = NSDateFormatterStyle.Short,
       TimeStyle = NSDateFormatterStyle.None,
       TimeZone = NSTimeZone.FromGMT(0),
 view.EditingBegan += (sender, e) =>
       if (string.IsNullOrEmpty(view.StringValue))
            view.StringValue = dateFormatter.EditingStringFor(DateTime.Today.ToNSDate());
view.EditingEnded += (sender, e) =>

It works when cell contains some date, I can edit it. When I delete cell content I'll correctly get null NSDate value. But then it is not possible to start editing again when text is empty. I'd like to achieve behavior when user starts editing on empty cell, it would insert current day automatically (to create date template in correct format - in my case mm/dd/yy).
I've implemented EditingEnded delegate, but it is not called in case when cell is empty when I try to start editing.
I've also tried to override NSTextField's ShouldBeginEditing(), AcceptsFirstResponder(), BecomeFirstResponder() but nothing is called when cell is empty.
Even after update when text is deleted I've tried to remove formatter using view.Formatter = null; but it does not allow setting Formatter property to null although it is default value.
Any ideas what could I do? Thank you.

Sign In or Register to comment.