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

Null reference exception occurs when adding a new row for the DateTime column type in SfDataGrid - From 179495

But I found another strange problem; the DateTime column crash the application (System.NullReferenceException), when I try to add a new row and then to edit it.

A sample of the column:

            sfDataGrid1.Columns.Add(new GridDateTimeColumn()
{
MappingName = "Date",
HeaderText = "Data",
ColumnMemberType = typeof(DateTime),
Pattern = DateTimePattern.ShortDate,
AllowNull = true
});

3 Replies

VS Vijayarasan Sivanandham Syncfusion Team December 21, 2022 01:30 PM UTC

Hi Saverio,

We have checked the reported issue with the provided information. We are able to add the new row for the DateTime column type in SfDataGrid. Here, we have attached the tested sample and a video demo for your reference. Please have a look at this. Could you please confirm if we missed anything? If you are still facing the reported issue, modify the attached sample and share the video illustration of the reported issue. It will be helpful for us to check on it and provide you with a solution as soon as possible.

Regards,
Vijayarasan S


Attachment: SampleAndVideoDemo_9f7854a9.zip


SA Saverio replied to Vijayarasan Sivanandham December 21, 2022 11:34 PM UTC

Hi, I've attached the original modified project. In that case the problem still occurs.


Attachment: WF_SfDataGrid_ComboBox_ef19317a.7z


VD Vasanthkumar Durairaj Syncfusion Team December 22, 2022 02:20 PM UTC


Saverio,

The reported issue occurs because the instance is not created for the underlying collection, which is already stated in UG.

To resolve this, you can define the default constructor for underlying data. Otherwise, create an instance of data object by handling AddNewRowInitiating event.

Find the UG link and test sample.
https://help.syncfusion.com/windowsforms/datagrid/datamanipulation#addnewrow
Graphical user interface, text, application

Description automatically generated


Attachment: WF_SfDataGrid_ComboBox_bccdcb1c.zip

Loader.
Live Chat Icon For mobile
Up arrow icon