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.
Regarding #2:
In your previous posts you explained that my issue with casting e.Cell.Value is that because it is an Object and that I should take this up with Microsoft.
What I am asking is why then, given this idea, can I cast it to Decimal without an issue? If casting from an object to a primitive causes issues, then shouldn't it NOT work for Decimal? If e.Cell.Value.GetType() returns System.Decimal, and it is a RULE of the .NET Framework that a System.Decimal can be cast to a System.Double I am not seeing why this does not work unless the UltraWinGrid involved.
So, do you know that if the datatype from the database is float that I can cast e.Cell.Value to Double without an error?
melegant said: 1) In your tutorial on Grid Performance, you have some examples of lines of code: e.Row.Cells["Total"].Value = (double)e.Row.Cells["Quantity"].Value * (double)e.Row.Cells["Price"].Value; Interestingly enough, if I try this it does not work, it has to be: e.Row.Cells["Total"].Value = (decimal)e.Row.Cells["Quantity"].Value * (decimal)e.Row.Cells["Price"].Value;
1) In your tutorial on Grid Performance, you have some examples of lines of code:
e.Row.Cells["Total"].Value = (double)e.Row.Cells["Quantity"].Value * (double)e.Row.Cells["Price"].Value;
Interestingly enough, if I try this it does not work, it has to be:
e.Row.Cells["Total"].Value = (decimal)e.Row.Cells["Quantity"].Value * (decimal)e.Row.Cells["Price"].Value;
I guess the data type in the sample code is using double and not decimal, then.
melegant said: 2) Concerning your logic regarding not being able to cast an Object to Double that happens to be a decimal, why is not an issue to cast e.Cell.Value like this: (Decimal)e.Cell.Value but it is an issue to do this? (Double)e.Cell.Value
2) Concerning your logic regarding not being able to cast an Object to Double that happens to be a decimal, why is not an issue to cast e.Cell.Value like this:
(Decimal)e.Cell.Value
but it is an issue to do this?
(Double)e.Cell.Value
I'm not sure I understand. Why is this puzzling to you? Are you under the impression that double and decimal are the same thing? Because they are not.
(double)e.cell.Value will work just fine - if the DataType of the column is double and not decimal.
(decimal)e.cell.Value will work just fine - if the DataType of the column is decimal.
There are a few things here that I have an issue with:
I believe the difference here is that you are not attempting to convert a decimal to double. You are converting an object (that happens to be a decimal).
This code works fine:
decimal de = 5.5M; // Declare de as decimal double db = (double)de; Debug.WriteLine(db.ToString());
But this does not:
object de = 5.5M; // Declare de as object double db = (double)de; Debug.WriteLine(db.ToString());
Notice the difference in the first line where I declare de as object instead of decimal.
Anyway, none of this has anything to do with the WinGrid. So if you feel this is wrong, you will need to take it up with Microsoft. :)
Not according to this table:
http://msdn.microsoft.com/en-us/library/yht2cx7b.aspx
and here
http://msdn.microsoft.com/en-us/library/364x0z75.aspx