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.
Unfortunately, activation email could not send to your email. Please try again.

Null DateTime Column Values

Thread ID:

Created:

Updated:

Platform:

Replies:

62699 Jun 20,2007 02:04 PM Jun 21,2007 02:00 PM Windows Forms 8
loading
Tags: GridControl
Tod Golding
Asked On June 20, 2007 02:04 PM

If I bind a column to a DateTime property, how can I allow that column to be null? Basically, I don't want that column to remain "empty" unless the users specifically enters a date. Is there a way to do this?

haneefm [Syncfusion]
Replied On June 20, 2007 02:16 PM

Hi Tod,

You can use the DBNull.Value for DateTime Column to make the empty cell. Please try this code snippet and let me know if this helps.

[c#]
this.grid.Table.Records[1].SetValue("ColumnName", DBNull.Value);

Best regards,
Haneef

Tod Golding
Replied On June 20, 2007 02:58 PM

I'm not sure that will work. That allows me to manually set a specific row's value to null. I want any new row being added to have a default of null. So, I want the cell to be empty for each new row being added. How do I achieve that?



>Hi Tod,

You can use the DBNull.Value for DateTime Column to make the empty cell. Please try this code snippet and let me know if this helps.

[c#]
this.grid.Table.Records[1].SetValue("ColumnName", DBNull.Value);

Best regards,
Haneef

haneefm [Syncfusion]
Replied On June 20, 2007 04:06 PM

Hi Tod,

Please refer this thread
http://www.syncfusion.com/Support/forums/message.aspx?MessageID=37663

Best regards,
Haneef

Tod Golding
Replied On June 20, 2007 04:34 PM

This doesn't fully solve the problem. While I can now initalize the column to a null value, the cell fails when I try to add the new row because it says it can't convert from DBNull to DateTime.

>Hi Tod,

Please refer this thread
http://www.syncfusion.com/Support/forums/message.aspx?MessageID=37663

Best regards,
Haneef

haneefm [Syncfusion]
Replied On June 20, 2007 08:13 PM

Hi Tod,

Here is a minimal sample that shows you "How to set the default value in a AddNewRecord using CurrentContextChange event of the grid?". Please try this and let me know if this helps.
AddNewDefaultValue.zip

Best regards,
Haneef

Tod Golding
Replied On June 21, 2007 01:59 AM

Your example relies on a DataTable as a source (which understands how to process conversion of the null value). Try this with a binding to a custom object that has a DateTime value as one of its properties. Then, as best I can tell, the coversion fails.

>Hi Tod,

Here is a minimal sample that shows you "How to set the default value in a AddNewRecord using CurrentContextChange event of the grid?". Please try this and let me know if this helps.
AddNewDefaultValue.zip

Best regards,
Haneef

Tod Golding
Replied On June 21, 2007 01:59 AM

Your example relies on a DataTable as a source (which understands how to process conversion of the null value). Try this with a binding to a custom object that has a DateTime value as one of its properties. Then, as best I can tell, the coversion fails.

>Hi Tod,

Here is a minimal sample that shows you "How to set the default value in a AddNewRecord using CurrentContextChange event of the grid?". Please try this and let me know if this helps.
AddNewDefaultValue.zip

Best regards,
Haneef

haneefm [Syncfusion]
Replied On June 21, 2007 02:00 PM

Hi Tod,

You can make a DateTime column of your custom collection as a Nullable column. Below are the code snippet for setting the nullable column.

private DateTime? date;
public DateTime? Date
{
get
{return this.date;}
set
{ this.date = value; }
}

Please refer to the attached sample for implementation and let me know if this helps.
ModifiedAddNewDefaultValue.zip

Best regards,
Haneef

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;