GGC with Date column that allows nulls is crashing when filtering

Hi Community! 

I have a ggc where one of the columns data type is Date in the format of  dd-MMM-yyyy. But when i try to filter by this column (Date To) my application crashes because I'm allowing nulls in a date column. Is there a way to get around a nullable date column ? Any help would be much appreciated!



 


3 Replies

BT Balamurugan Thirumalaikumar Syncfusion Team July 23, 2021 11:48 AM UTC

Hi Mohammed, 

Thank you for interesting in Syncfusion products. 

We have checked your query “GGC with Date column that allows nulls is crashing when filtering’ at our end. In order to achieve your requirement we suggest you to use DBNull.Value for DateTime Column to make the empty cell. Please refer below code snippet and sample for your reference. 
 
Code Snippet 
this.gridGroupingControl1.Table.Records[3].SetValue("Date", DBNull.Value); 


Please let us know if you would require any other assistance. we will be happy to assist you. 

Thanks & Regards, 
Balamurugan Thirumalaikumar  



MS Mohammed Shafeel July 25, 2021 10:37 AM UTC

Hi  Balamurugan, 

Thanks for the help. I have tried to do it your way but the field already has a type of System.DateTime? and I cant' use System.DBNull unfortunately. I've included a screen as to how i am doing it. my data source is binded to a list as well 





BT Balamurugan Thirumalaikumar Syncfusion Team July 26, 2021 08:44 AM UTC

Hi Mohammed, 
 
Thank you for your update. 
 
We have checked your query “do it your way but the field already has a type of System.DateTime? and I cant' use System.DBNull unfortunately” at our end. We would like to let you know that you can't assign the DBNull value to a DateTime type property because the DateTo property is already a DateTime type, so you can't insert the DBNull value. To overcome the reported scenario, we suggest that you check the null value in the DateTime column and assign the DBNull value using the SetValue method, which takes an object as a second parameter. Please refer the following code snippet for your reference. 
 
Code Snippet 
//Event Subscription 
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo; 
 
//Event Customization 
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
    foreach(var record in gridGroupingControl1.Table.Records) 
    { 
        if(record.GetValue("Date") == null) 
        { 
            this.gridGroupingControl1.Table.Records[record.GetSourceIndex()].SetValue("Date", DBNull.Value); 
        } 
    } 
} 
 
We have prepared the simple sample for your reference. Please refer it below. 
 
 
Please let us know if you would require any other assistance. we will be happy to assist you. 
 
Balamurugan Thirumalaikumar  
 


Loader.
Up arrow icon