AD
Administrator
Syncfusion Team
August 26, 2003 03:51 PM UTC
I suspect this has to do with formatting and cellvaluetype. Are you setting the style.Format property and the style.CellValueType for this cell?
Would it be possible for you to upload a little project showing the problem?
SA
scot adams
August 27, 2003 08:14 PM UTC
Behaves the same with or without the dateStyle.Format and dateStyle.CellValueType.
Actually a better solution would be to apply an edit mask as well. But I can't seem to apply the calendar and the mask to the cell.
//row is coming from Dataset
//gridAttributes is regular grid, not databound
if((int)row["ATTR_TYPE_ID"] == 13)
{
GridStyleInfo dateStyle = gridAttributes[gridrow,2];
dateStyle.CellType = "MonthCalendar";
dateStyle.Format = "d";
dateStyle.CellValueType = typeof(System.DateTime);
}
AD
Administrator
Syncfusion Team
August 27, 2003 08:31 PM UTC
Attached is a little sample. In CurrentCellShowingDropDown, try code like:
private void gridControl1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
if(this.gridControl1[cc.RowIndex, cc.ColIndex].CellType == "MonthCalendar")
{
try
{
DateTime dt = DateTime.Parse(cc.Renderer.ControlText);
}
catch
{
cc.Renderer.Control.Text = "";
}
}
}
CC
Cyrille Claustre
March 25, 2004 06:54 AM UTC
Hi.
I''ve got excatly the same problem. All the properties are set correctly (i.e. format, cellvaluetype, etc) but I always get this exception when deactivating the cell, even if the value was picked from the calendar ! (not typed in).
I handled both CurrentCellShowingDropDown and CurrentCellDeactivating events with this code :
GridCurrentCell cc = detailStudentGrid.CurrentCell;
if(this.detailStudentGrid[cc.RowIndex, cc.ColIndex].CellType == "MonthCalendar")
{
try
{
DateTime dt = DateTime.Parse(cc.Renderer.ControlText);
}
catch
{
cc.Renderer.Control.Text = "";
}
}
What can I do ?
AD
Administrator
Syncfusion Team
March 25, 2004 11:22 AM UTC
Check to make sure this event is being hit.
If it is being hit, then maybe the format you have provided is not the same as the regional settings on the system which is what DateTime.Parse will use by default.
So, one thing you can try is to force the string being returned to fit the format you have specified.
So, after the line
DateTime dt = DateTime.Parse(cc.Renderer.ControlText);
add a line like
cc.Renderer.Control.Text = dt.ToString("MMddyyyy"); //change MMddyyyy to the format you provide in the style.
If this doesn''t resolve it, if you post a little sample showing the problem an dprvide details like regional setting and grid version, we can look at it here. You can also submit a Direct Trac support incident with this information if you cannot post it here.
CB
CBurrows
May 6, 2005 02:27 PM UTC
(I am in C# for Windows Forms (not web))
I just started getting this message on 5/4/05! I''m not parsing and before
this, my program worked just fine. Here''s a posting I put on another site
in desperation:
Greetings,
I don''t know how long ago this conversation took place, but am desperate
for help with the same problem. Up until two days ago, my code for
inserting a record into a table worked fine. Update still works, but on
insert, I am getting this dialog box now:
System.FormatException: The string was not recognized as a valid DateTime.
There is a unknown word starting at index 0
It''s driving me crazy. Mostly because this has worked fine until now.
There are four dates (though I removed TimeStamp to try to fix) and I have
tried everything!
One important thing to note is that my product is completely in English,
having nothing to do with other timezones or anything like that.
Anyway, I don''t know if anyone can (or has time to) help. Just thought I''d
try and ask. :)
Carolyn
Here''s some more information:
----------------------------------------------------------------------------
----
SQL Server Table I''m trying to add records to:
(NAME: SystemParameter)
2 SystemParameterID int 4 0 (<----Primary key with identity seed)
0 SystemParameterTypeID int 4 0
0 PersonID int 4 1
0 SystemParameterEffectiveDate datetime 8 0
0 SystemParameterEndDate datetime 8 1
0 SystemParameterValue varchar 255 1
0 LastUpdateDate datetime 8 1
1 LastUpdateUser varchar 255 1
----------------------------------------------------------------------------
----
(Stored Proc: InsertSystemParameter)
(NOTE: Removed Timestamp which didn''t help)
CREATE procedure dbo.InsertSystemParameter
(
@SystemParameterID int output,
@SystemParameterTypeID int,
@PersonID int,
@SystemParameterEffectiveDate datetime = null,
@SystemParameterEndDate datetime = null,
@SystemParameterValue varchar(255) = null,
@LastUpdateDate datetime = null,
@LastUpdateUser varchar(50) = null
/*,
@TimeStamp timestamp = null*/
)
as
insert into SystemParameter
(
SystemParameterTypeID,
PersonID,
SystemParameterEffectiveDate,
SystemParameterEndDate,
SystemParameterValue,
LastUpdateUser
)
values
(
@SystemParameterTypeID,
@PersonID,
@SystemParameterEffectiveDate,
@SystemParameterEndDate,
@SystemParameterValue,
@LastUpdateUser
)
select @SystemParameterID = @@Identity
GO
----------------------------------------------------------------------------
----
(CODE - You can see where I commented out almost everything I tried!)
private void SaveSystemParameter(
int systemParameterID,
int systemParameterTypeID,
int personID,
//System.DateTime systemParameterEffectiveDate,
//System.DateTime systemParameterEndDate,
string systemParameterEffectiveDate,
string systemParameterEndDate,
string systemParameterValue,
string lastUpdateUser,
DsSystemParameter dsSystemParameter)
{
DsSystemParameter.SystemParameterRow systemParameterRow;
//-//bool staffingGuideTypeProductivityFlag = false;
//-//BcStaffingGuideType bcStaffingGuideType = new BcStaffingGuideType
(this.ContextMoniker);
//-//staffingGuideTypeProductivityFlag =
bcStaffingGuideType.IsProductivityType(staffingGuideTypeID, dsStaffingGuide)
;
//New Record?
if(systemParameterID.Equals(-1))
{
systemParameterRow = GetSystemParameterRow(systemParameterTypeID,
personID, dsSystemParameter);
}
//Existing Record
else
{
systemParameterRow = GetSystemParameterRow(systemParameterID,
dsSystemParameter);
}
//if the system Parameter wasn''t located in the dataset
if (systemParameterRow == null)
{
//if new record, then create new row
if(systemParameterID.Equals(-1))
{
systemParameterRow =
dsSystemParameter.SystemParameter.NewSystemParameterRow();
}
//else could not find record
else
{
throw Utilities.GetMissingRecordException("SystemParameter");
}
}
//else, it was found, and attempting to add new, then raise an error
else if (systemParameterID.Equals(-1))
{
throw Utilities.GetDuplicateRecordException("SystemParameter");
}
//update fields
systemParameterRow.SystemParameterTypeID = systemParameterTypeID;
systemParameterRow.PersonID = personID;
//Used to work:
systemParameterRow.SystemParameterEffectiveDate =
Convert.ToDateTime(systemParameterEffectiveDate) ;
//None of these work: //-//Indicates groups of lines tried
together.
//-//CultureInfo cultureInfo = new CultureInfo("en-US");
//-//DateTime dt = DateTime.ParseExact
(systemParameterEffectiveDate, "D", cultureInfo);
//-//systemParameterRow.SystemParameterEffectiveDate = dt;
//DateTime dt = DateTime.ParseExact
(systemParameterEffectiveDate, "dd/MM/yy", null);
//-//systemParameterEffectiveDate = Convert.ToDateTime
(systemParameterEffectiveDate).ToUniversalTime().ToString( format );
//-//systemParameterRow.SystemParameterEffectiveDate =
Convert.ToDateTime(systemParameterEffectiveDate);
//systemParameterRow.SystemParameterEffectiveDate =
ParseDateTime(systemParameterEffectiveDate) ;
//systemParameterRow.SystemParameterEffectiveDate =
Convert.ToDateTime(systemParameterEffectiveDate).ToLocalTime() ;
//systemParameterRow.SystemParameterEffectiveDate =
DateTime.Parse(systemParameterEffectiveDate,
//
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
//systemParameterRow.SystemParameterEffectiveDate =
System.DateTime.ParseExact(systemParameterEffectiveDate, @"yyyy\/MM\/dd
HH:mm:ss", null);
//systemParameterRow.SystemParameterEffectiveDate =
System.DateTime.Parse("05/05/2005") ;
//systemParameterRow.SystemParameterEffectiveDate =
System.DateTime.Parse(systemParameterEffectiveDate) ;
if (! systemParameterEndDate.Equals(String.Empty ) )
{
systemParameterRow.SystemParameterEndDate =
Convert.ToDateTime(systemParameterEndDate); //.ToLocalTime();
}
else
{
//None of these work.
//systemParameterRow.SystemParameterEndDate =
System.DateTime.Now;
//systemParameterRow.SystemParameterEndDate =
DBNull.Value;
//systemParameterRow.SystemParameterEndDate =
Convert.ToDateTime(DBNull.Value.ToString());
//systemParameterRow.SystemParameterEndDate =
Convert.ToDateTime(String.Empty.ToString());
//systemParameterRow.SystemParameterEndDate =
DateTime.Parse(systemParameterEffectiveDate,
//
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
}
systemParameterRow.SystemParameterValue = systemParameterValue;
//if adding new record
if(systemParameterID.Equals(-1))
{
dsSystemParameter.SystemParameter.AddSystemParameterRow
(systemParameterRow);
}
systemParameterRow.LastUpdateUser =
lastUpdateUser;
//systemParameterRow.LastUpdateDate =
System.DateTime.Now;
//Save Record
SaveData(dsSystemParameter);
//
}
public void SaveData(DsSystemParameter dsSystemParameter)
{
_dcSystemParameter.SaveTable( dsSystemParameter );
//cb temporary removed_dwSystemParameter.SaveData(0, dsSystemParameter);
}
----------------------------------------------------------------------------
----
(Save table just executes the stored proc called InsertSystemParameter)
CB
CBurrows
May 6, 2005 06:38 PM UTC
The problem is fixed. We are using datasets and data containers. One of
my coworkers noticed that the Dc and the stored procedure parameters were
out of synch. No one will admit to it, though.
Oh, well. Relief!
Thanks again!
>(I am in C# for Windows Forms (not web))
>
>I just started getting this message on 5/4/05! I''m not parsing and before
>this, my program worked just fine. Here''s a posting I put on another site
>in desperation:
>
>Greetings,
>
>I don''t know how long ago this conversation took place, but am desperate
>for help with the same problem. Up until two days ago, my code for
>inserting a record into a table worked fine. Update still works, but on
>insert, I am getting this dialog box now:
>
>System.FormatException: The string was not recognized as a valid DateTime.
>There is a unknown word starting at index 0
>
>It''s driving me crazy. Mostly because this has worked fine until now.
>There are four dates (though I removed TimeStamp to try to fix) and I have
>tried everything!
>
>One important thing to note is that my product is completely in English,
>having nothing to do with other timezones or anything like that.
>
>Anyway, I don''t know if anyone can (or has time to) help. Just thought I''d
>try and ask. :)
>
>Carolyn
>
>Here''s some more information:
>
>----------------------------------------------------------------------------
>----
>SQL Server Table I''m trying to add records to:
>(NAME: SystemParameter)
>2 SystemParameterID int 4 0 (<----Primary key with identity seed)
>0 SystemParameterTypeID int 4 0
>0 PersonID int 4 1
>0 SystemParameterEffectiveDate datetime 8 0
>0 SystemParameterEndDate datetime 8 1
>0 SystemParameterValue varchar 255 1
>0 LastUpdateDate datetime 8 1
>1 LastUpdateUser varchar 255 1
>
>----------------------------------------------------------------------------
>----
>(Stored Proc: InsertSystemParameter)
>(NOTE: Removed Timestamp which didn''t help)
>
>CREATE procedure dbo.InsertSystemParameter
>(
>@SystemParameterID int output,
>@SystemParameterTypeID int,
>@PersonID int,
>@SystemParameterEffectiveDate datetime = null,
>@SystemParameterEndDate datetime = null,
>@SystemParameterValue varchar(255) = null,
>@LastUpdateDate datetime = null,
>@LastUpdateUser varchar(50) = null
>/*,
>@TimeStamp timestamp = null*/
>)
>as
>
>
> insert into SystemParameter
> (
> SystemParameterTypeID,
> PersonID,
> SystemParameterEffectiveDate,
> SystemParameterEndDate,
> SystemParameterValue,
> LastUpdateUser
> )
> values
> (
> @SystemParameterTypeID,
> @PersonID,
> @SystemParameterEffectiveDate,
> @SystemParameterEndDate,
> @SystemParameterValue,
> @LastUpdateUser
> )
> select @SystemParameterID = @@Identity
>GO
>
>----------------------------------------------------------------------------
>----
>(CODE - You can see where I commented out almost everything I tried!)
> private void SaveSystemParameter(
> int systemParameterID,
> int systemParameterTypeID,
> int personID,
> //System.DateTime systemParameterEffectiveDate,
> //System.DateTime systemParameterEndDate,
> string systemParameterEffectiveDate,
> string systemParameterEndDate,
> string systemParameterValue,
> string lastUpdateUser,
> DsSystemParameter dsSystemParameter)
> {
>
> DsSystemParameter.SystemParameterRow systemParameterRow;
> //-//bool staffingGuideTypeProductivityFlag = false;
>
> //-//BcStaffingGuideType bcStaffingGuideType = new BcStaffingGuideType
>(this.ContextMoniker);
> //-//staffingGuideTypeProductivityFlag =
>bcStaffingGuideType.IsProductivityType(staffingGuideTypeID, dsStaffingGuide)
>;
>
> //New Record?
> if(systemParameterID.Equals(-1))
> {
> systemParameterRow = GetSystemParameterRow(systemParameterTypeID,
>personID, dsSystemParameter);
> }
> //Existing Record
> else
> {
> systemParameterRow = GetSystemParameterRow(systemParameterID,
>dsSystemParameter);
> }
>
> //if the system Parameter wasn''t located in the dataset
> if (systemParameterRow == null)
> {
> //if new record, then create new row
> if(systemParameterID.Equals(-1))
> {
> systemParameterRow =
>dsSystemParameter.SystemParameter.NewSystemParameterRow();
> }
> //else could not find record
> else
> {
> throw Utilities.GetMissingRecordException("SystemParameter");
> }
> }
> //else, it was found, and attempting to add new, then raise an error
> else if (systemParameterID.Equals(-1))
> {
> throw Utilities.GetDuplicateRecordException("SystemParameter");
> }
>
> //update fields
>
> systemParameterRow.SystemParameterTypeID = systemParameterTypeID;
> systemParameterRow.PersonID = personID;
>
> //Used to work:
> systemParameterRow.SystemParameterEffectiveDate =
>Convert.ToDateTime(systemParameterEffectiveDate) ;
>
> //None of these work: //-//Indicates groups of lines tried
>together.
>
> //-//CultureInfo cultureInfo = new CultureInfo("en-US");
> //-//DateTime dt = DateTime.ParseExact
>(systemParameterEffectiveDate, "D", cultureInfo);
> //-//systemParameterRow.SystemParameterEffectiveDate = dt;
>
> //DateTime dt = DateTime.ParseExact
>(systemParameterEffectiveDate, "dd/MM/yy", null);
>
> //-//systemParameterEffectiveDate = Convert.ToDateTime
>(systemParameterEffectiveDate).ToUniversalTime().ToString( format );
> //-//systemParameterRow.SystemParameterEffectiveDate =
>Convert.ToDateTime(systemParameterEffectiveDate);
>
> //systemParameterRow.SystemParameterEffectiveDate =
>ParseDateTime(systemParameterEffectiveDate) ;
> //systemParameterRow.SystemParameterEffectiveDate =
>Convert.ToDateTime(systemParameterEffectiveDate).ToLocalTime() ;
> //systemParameterRow.SystemParameterEffectiveDate =
>DateTime.Parse(systemParameterEffectiveDate,
> //
>System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
> //systemParameterRow.SystemParameterEffectiveDate =
>System.DateTime.ParseExact(systemParameterEffectiveDate, @"yyyy\/MM\/dd
>HH:mm:ss", null);
> //systemParameterRow.SystemParameterEffectiveDate =
>System.DateTime.Parse("05/05/2005") ;
> //systemParameterRow.SystemParameterEffectiveDate =
>System.DateTime.Parse(systemParameterEffectiveDate) ;
> if (! systemParameterEndDate.Equals(String.Empty ) )
> {
> systemParameterRow.SystemParameterEndDate =
>Convert.ToDateTime(systemParameterEndDate); //.ToLocalTime();
> }
> else
> {
> //None of these work.
> //systemParameterRow.SystemParameterEndDate =
>System.DateTime.Now;
> //systemParameterRow.SystemParameterEndDate =
>DBNull.Value;
> //systemParameterRow.SystemParameterEndDate =
>Convert.ToDateTime(DBNull.Value.ToString());
> //systemParameterRow.SystemParameterEndDate =
>Convert.ToDateTime(String.Empty.ToString());
> //systemParameterRow.SystemParameterEndDate =
>DateTime.Parse(systemParameterEffectiveDate,
> //
>System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
>
> }
> systemParameterRow.SystemParameterValue = systemParameterValue;
>
> //if adding new record
> if(systemParameterID.Equals(-1))
> {
> dsSystemParameter.SystemParameter.AddSystemParameterRow
>(systemParameterRow);
> }
> systemParameterRow.LastUpdateUser =
>lastUpdateUser;
> //systemParameterRow.LastUpdateDate =
>System.DateTime.Now;
> //Save Record
> SaveData(dsSystemParameter);
> //
> }
>
> public void SaveData(DsSystemParameter dsSystemParameter)
> {
> _dcSystemParameter.SaveTable( dsSystemParameter );
> //cb temporary removed_dwSystemParameter.SaveData(0, dsSystemParameter);
> }
>
>----------------------------------------------------------------------------
>----
>(Save table just executes the stored proc called InsertSystemParameter)
>
>
>
>