Hello,
I have a decimal column which I format using the column.format to 2 decimal places. I can see that this changes the text but not the underlying value. What
is the best way to round the underlying value? My database is crashing trying to save too many decimal places.
Do I have to use the IEditorDataFilter?
regards
Darren
Hello Darren,
What database are you using? Microsoft SQL Server automatically rounding decimal value, when scale of value is more than scale of the column. So your database shouldn’t be “crashing” if you are synchronize the type of what you insert with database type of the column where you insert.
If you want to rounding value of the cell you could use _BeforeCellUpdate event of the grid, and round cell value depends on your requirements.
Let me know if you have any further questions.
Thanks for the response Hristo. I'm using Sybase ASE 12 with the .NET Sybase drivers unfortunately. I tried using the BeforeCellUpdate but it doesn't seem to allow you to change the value.
I also tried BeforeExitEditMode but I also need to make sure that any calculated fields get rounded as well, as they will cause a crash too.
So I thought perhaps I could use the Datafilter , but so far I haven't gotten that to work.
So you want to prevent your users from entering more than 2 decimal places? In that case, you should use the MaskInput property on the column. Set it to something like:
"nnn.nn"
I am just checking about the progress of this issue. Did you need any further assistance on this issue? Did you solve your issue accordingly to the information that I provided you?
Let me know if you need any further assistance.
Thank you for using Infragistics Components.
Hello Daren,
Just checking if resolve your issue or if you require any further assistance on the matter.
What else you could try if the masking is not solving your issue is directly to manipulate the value of the cell. You could handle _AfterCellUpdate and put the following code:
if (e.Cell.Column.Key == "value" && !string.IsNullOrEmpty(e.Cell.Value.ToString()))
{
string s = e.Cell.Value.ToString();
CultureInfo ci = Application.CurrentCulture;
int sepindex = s.IndexOf(ci.NumberFormat.CurrencyDecimalSeparator);
if (sepindex > 0 && s.Length - sepindex > 3)
decimal d = decimal.Parse(e.Cell.Value.ToString());
e.Cell.Value = Math.Round(d, 2);
}
Hi Darren,
This code is very hard to read because of the formatting. But EditorToOwner controls the transition of the value from the editor (think of this as the cell in the grid) to the owner (which is the data source field). So this seems like it's exactly what you need. I can't see any reason why that would not work, unless there's something wrong with your data filter.
I thought I'd try the datafilter so I did this, which seems to update the Text but the value itself is still not updated to the new value.....
Then
.Format = BuildNumberFormatString(objLwCalcMethodDetailItem.DecimalPlaces)
EditorWithText
NumericEd.DataFilter =
DecimalPlacesConverter
Ucolumn.Editor = NumericEd
If
Public
Infragistics.Win.IEditorDataFilter
Infragistics.Win.EditorDataFilterConvertArgs) _
IEditorDataFilter.Convert
conversionArgs.Direction
ConversionDirection.EditorToOwner
_
conversionArgs.Value.GetType()
conversionArgs.Handled =
True
(conversionArgs.Value, System.Decimal)
= Math.Round(OldValue, 2)
RoundedValue
Select
Nothing
Function
End
Class
Hi Mike,
Whereas I can mask the input for the fields the user enters, if it results in a calculated column having more than 6 decimal places it still causes a problem.
I thought I could use the datafilter EditorToOwner to convert it but it only seems to change the Text of the cell and not the underlying value.