Hi,
I have a grid that reads in a bunch of number values from a database. These values are only ever either INT or Decimal(x,x)
When I try this after a UltraGrid AfterCellUpdate
if((Double)e.Cell.Value > 0)
But recieve an error that specific cast is not valid. The type returned by e.cell.value is Decimal and the Value = 3 in this test.
Okay, I tried this again using the same code you are using and it looks like this is just a limitation of DotNet. It can't cast an object decimal directly into a double.
It looks like you will have to cast to a decimal first.This works:
decimal d = (Decimal)e.Cell.Value;if ((double)d > 0){ }
decimal d = (Decimal)e.Cell.Value;if ((double)d > 0){
}
Or another option would be to try to parse the value from a string:
double d; bool success = double.TryParse(e.Cell.Value.ToString(), out d); if (success && d > 0) {
Also , e.Cell.Value.GetType() == System.Decimal
The field in the database is Decimal(18,2)
Line of Code in AfterCellUpdate event.
if
((double)e.Cell.Value < 0)
System.InvalidCastException was unhandled by user code Message="Specified cast is not valid." Source="UGTest" StackTrace: at Mitsic.frmcEquipment.ugEquip_AfterCellUpdate(Object sender, CellEventArgs e) in C:\Documents and Settings\rand\My Documents\Visual Studio 2008\Projects\UGTest\UGTest\frmcUgTestt.cs:line 7532 at Infragistics.Win.UltraWinGrid.UltraGrid.OnAfterCellUpdate(CellEventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e) at Infragistics.Win.UltraWinGrid.UltraGridCell.SetValueInternal(Object value, Boolean suppressErrorMessagePrompt, Boolean fireInitializeRow, Boolean throwExceptionOnError, Boolean fireDataChanged) at Infragistics.Win.UltraWinGrid.UltraGridCell.SetValueInternal(Object value, Boolean suppressErrorMessagePrompt, Boolean fireInitializeRow, Boolean throwExceptionOnError) at Infragistics.Win.UltraWinGrid.UltraGridCell.SetValueInternal(Object value, Boolean suppressErrorMessagePrompt, Boolean fireInitializeRow) at Infragistics.Win.UltraWinGrid.UltraGridCell.CommitEditValue(Boolean& stayInEdit, Boolean fireDataError, Boolean forceDontThrowException, Boolean dontStoreInUndoHistory) InnerException:
I tried this out and it works just fine for me.
What exactly is the exception? What does the call stack look like?