We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

GridDateTimeColumn with null binded values

HI,

I have a GridDateTimeColumn column in a SFDataGrid whose binded to a property of type "DateTime?".
When the binded record has a value of null on that property, the cell displays the current date on itself instead of a blank cell as I espected.
Is there a way not to show the current date on that columns in such situations ?

In the same situation, supposing I'm able to fix the first problem, is there a way for the user to remove a date from a cell (that means to put to null the related binded property) ?

5 Replies

JS Jayapradha S Syncfusion Team February 19, 2016 12:36 PM UTC

Hi Silvio,

Thank you for contacting Syncfusion Support.

You can display a null value on GridDateTimeColumn using NullText and NullValue properties. Also you can remove date from the cell by setting CanEdit as True as shown in the below code example,

Code Example:

  <Syncfusion:GridDateTimeColumn MappingName="JoiningDate" 

                                               CanEdit="True" 

                                               NullText="" 
                                               NullValue="{x:Null}" />


We have prepared a sample for your requirement and please find the sample from the following location,
Sample Link: http://www.syncfusion.com/downloads/support/forum/122131/ze/DateTime_NullValue1715036667

Regards,
Jayapradha
 


SI Silvio February 19, 2016 02:39 PM UTC

I'm sorry but it seems your example doesn't work.

To further simplify the example I have changed the data initialization like this:


        private void PopulateCollection()
        {
            this.Clear();

          //  for (int i = 0; i < 700; i++)
            {
                BusinessObjects b = new BusinessObjects() { EmployeeName = "Mart", JoiningDate=new DateTime(2013,3,3), EmployeeAge = 45, EmployeeArea = "USA", EmployeeSalary = 33000, ExperienceInMonth = 10, EmployeeGender = "Male" , Rating = 2, CheckBoxValue = true};
                this.Add(b);
                b = new BusinessObjects() { EmployeeName = "Peter", EmployeeAge = 35, EmployeeArea = "UK", EmployeeSalary = 5678, ExperienceInMonth = 10, EmployeeGender = "Male", Rating = 1, CheckBoxValue = true };
                this.Add(b);
            }

        }


As you can see, the first record set a date equal to 3-3-2013, while the second record leaves the date to null.

But the datagrid, for the second record, shows the current date and not an empty cell.
In addition, when I try to remove the data, as soon as I finish editing, the current date again is placed on the cell instead of an empty string.
See the attached image.

Attachment: Cattura_92bace23.zip


SR Sivakumar R Syncfusion Team February 19, 2016 02:59 PM UTC

Hi Silvio,

You can allow null values in GridDateTimeColumn by setting AllowNullValue property to true.

<Syncfusion:GridDateTimeColumn MappingName="JoiningDate"
                                CanEdit="True"  AllowNullValue="True"/>


documentation :
http://help.syncfusion.com/wpf/sfdatagrid/column-types?cs-save-lang=1&cs-lang=xaml#null-value-support-1

Thanks,
Sivakumar



SI Silvio replied to Sivakumar R February 19, 2016 03:05 PM UTC

Hi Silvio,

You can allow null values in GridDateTimeColumn by setting AllowNullValue property to true.

<Syncfusion:GridDateTimeColumn MappingName="JoiningDate"
                                CanEdit="True"  AllowNullValue="True"/>


documentation :
http://help.syncfusion.com/wpf/sfdatagrid/column-types?cs-save-lang=1&cs-lang=xaml#null-value-support-1

Thanks,
Sivakumar


Thank you very much! Now it really works!


AP Ashwini Paranthaman Syncfusion Team February 22, 2016 12:59 PM UTC

Hi Silvio,
Thank you for the update.
Please let us know if you need any other assistance.
Regards,
Ashwini P.

Loader.
Live Chat Icon For mobile
Up arrow icon