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
2589
Cannot set DateTime value in DateColumn to null
posted

Hello,

This is a class I use to display on grid:

public class Person :INotifyPropertyChanged

    {

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)

        {

            if (PropertyChanged != null)

            {

                PropertyChanged(this, new PropertyChangedEventArgs(info));

            }

        }



        private string _company;

        private DateTime? _date;

        public int ID { get; set; }

        public string Company

        {

            get { return _company; }

            set { 

                if (string.IsNullOrEmpty(value))

                    throw new Exception("Company must not be empty");

                _company = value;

                NotifyPropertyChanged("Company");

            }

        }

        public DateTime? Date

        {

            get { return _date; }

            set

            {

                _date = value;

                NotifyPropertyChanged("Date");

            }

        }


        public string Name { get; set; }

        public KeyValue Field { get; set; }

        public Person(int id, string name, string comp, DateTime date, KeyValue field)

        {

            ID = id;

            Name = name;

            Company = comp;

            Date = date;

            Field = field;

        }


        public Person()

        {            

        }        

    }

And this is a part of XAML  which displays Date property:

<igGrid:TemplateColumn Key="Date">

                    <igGrid:TemplateColumn.HeaderTemplate>

                        <DataTemplate>

                            <TextBlock Text="Date" />

                        </DataTemplate>

                    </igGrid:TemplateColumn.HeaderTemplate>

                    <igGrid:TemplateColumn.ItemTemplate>

                        <DataTemplate>

                            <TextBlock Text="{Binding Date}"/>                            

                        </DataTemplate>

                    </igGrid:TemplateColumn.ItemTemplate>

                    <igGrid:TemplateColumn.EditorTemplate>

                        <DataTemplate>

                            <controls:DatePicker Text="{Binding Date, Mode=TwoWay}" />

                        </DataTemplate>

                    </igGrid:TemplateColumn.EditorTemplate>

                </igGrid:TemplateColumn>

Each time I enter edit mode and clear date value, and then move cursor to next row or cell, Date cell won't become empty and empty date won't save to datasource. What is the problem?

BTW the same thing happens when I'm using DateColumn.

Thank you.

Parents
No Data
Reply
  • 21382
    Suggested Answer
    posted

    Using the Date Column I was not able to reproduce your results,

    <iggrid:XamWebGrid x:Name="grid">

     

    </iggrid:XamWebGrid>

     

          public class Person : INotifyPropertyChanged

          {

                private DateTime? _dob;

                public string Name { get; set; }

                public int Age { get; set; }

                public DateTime? DOB

                {

                      get

                      {

                            return this._dob;

                      }

                      set

                      {

                            if (this._dob != value)

                            {

                                  this._dob = value;

                                 

                            }

                      }

                }

     

                #region INotifyPropertyChanged Members

     

                public event PropertyChangedEventHandler PropertyChanged;

     

                #endregion

          }

     

     

                public MainPage()

                {

                      InitializeComponent();

     

                     

     

                      this.grid.EditingSettings.AllowEditing = EditingType.Cell;

     

                      ObservableCollection<Person> p = new ObservableCollection<Person>();

                      p.Add(new Person() { Name = "bob", Age = 2, DOB= DateTime.Now });

                      this.grid.ItemsSource = p;         

                     

                }

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    Using the TemplateColumn I was able to reproduce you behavior, but that is because of a quirk in the DatePicker control.  The DatePicker doesn't finalize until after the blur on the control is called by the framework when entering text.  By this time the binding has already been called to update.

    This was one of the reasons why we created a Date Column.

    Since I am able to null out the text of a DateColumn, could you provide either a sample or explicit steps to reproduce your issue?

Children