|
|
|
|
Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
Andrew Hafer
|
Feb 3, 2007 - 5:36 PM
|
Hello.
I need to create a date cell that can also be blank in cases where the date isn’t known. Can I accomplish this with the DateTime cell?
Thanks.
|
|
Paddy
|
Dec 30, 2010 - 7:48 PM
|
When I try to use this code in my application, I am getting an error on line: cellStyle.TextColor = cellStyle.BackgroundColor The error is:
Argument Exception
Color cannot be set to Color [Empty]
|
|
Technical Support
|
Jan 5, 2011 - 9:53 AM
|
Sorry, but we do not fully understand in which context your code is used and what are you trying to achieve. Could you send us a more detailed description of the problem?
|
|
Technical Support
|
Feb 5, 2007 - 8:09 AM
|
The DateTime type does not support the "empty" value internally and there is no way to assign it to null except for using nullable types. We can regard your feature as a feature request.
You could however use its Minimum Value property to mark it as being empty.
|
|
Andrew Hafer
|
Feb 5, 2007 - 10:45 PM
|
Thank for your answer. Could you please expand upon both a) assigning it to null using nullable types and b) using Minimum Value
Thanks!
|
|
Technical Support
|
Feb 6, 2007 - 6:49 AM
|
We are sorry for being vague. Here are the details.
a) You cannot use nullable types at the moment because this is not supported in the cell classes. The date/time cell is using the DateTime type, not Nullable<DateTime> . We mentioned this just to show the possible way we are going to resolve this issue.
b) You can just use a small date value (any date that will be used as a stand-in for null) as a replacement for <empty> . You can also adjust the grid so this stand-in value will be hidden in cells (so such a cell will look like a blank cell) and act as being empty until the user changes the value. For example, you could use the following code:
[C#]
private readonly DateTime _EmptyDateTime = new DateTime(1900, 1, 1); // Fill your "empty" data with this value.
private void boundGridControl1_ModifyCellStyle(object sender, ModifyCellStyleEventArgs e)
{
if(e.Cell.Column != MyDateTimeColumn)
return;
// Make "empty" values invisible in cells.
if (e.Cell.DataValue != null && ((DateTime)e.Cell.DataValue) == _EmptyDateTime)
{
DateTimeCellStyle cellStyle = (DateTimeCellStyle)e.Style;
cellStyle.TextColor = cellStyle.BackgroundColor;
cellStyle.SelectedTextColor = cellStyle.SelectedBackgroundColor;
cellStyle.HoveredTextColor = cellStyle.HoveredBackgroundColor;
cellStyle.SelectedHoveredTextColor = cellStyle.SelectedHoveredBackgroundColor;
}
}
[VB.NET]
Private ReadOnly _EmptyDateTime As DateTime = New DateTime(1900, 1, 1) ’ Fill your "empty" data with this value.
Private Sub boundGridControl1_ModifyCellStyle(ByVal sender As Object, ByVal e As ModifyCellStyleEventArgs)
If e.Cell.Column <> MyDateTimeColumn Then
Return
End If
’ Make "empty" values invisible in cells.
If Not e.Cell.DataValue Is Nothing AndAlso (CDate(e.Cell.DataValue)) = _EmptyDateTime Then
Dim cellStyle As DateTimeCellStyle = CType(e.Style, DateTimeCellStyle)
cellStyle.TextColor = cellStyle.BackgroundColor
cellStyle.SelectedTextColor = cellStyle.SelectedBackgroundColor
cellStyle.HoveredTextColor = cellStyle.HoveredBackgroundColor
cellStyle.SelectedHoveredTextColor = cellStyle.SelectedHoveredBackgroundColor
End If
End Sub
|
|