Ultragrid cell value format in edit mode
New DiscussionHi,
I’m trying to reproduce with an UltraGrid a behaviour we can reach with the standard Windows Forms DatagridView. With the standard grid there’s the possibility to override the methods GetFormattedValue and ParseFormattedValue in order to display/parse values with a custom behaviour:
protected override object GetFormattedValue(object value, int rowIndex,
ref DataGridViewCellStyle cellStyle,
TypeConverter valueTypeConverter,
TypeConverter formattedValueTypeConverter,
DataGridViewDataErrorContexts context)
{
if (value != null && value != DBNull.Value)
{
if (this.RowIndex == -1 || !this.IsInEditMode)
value = FixDecimalPlaces(value, cellStyle);
}
return base.GetFormattedValue(value, rowIndex, ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context);
}
public override object ParseFormattedValue(object formattedValue,
DataGridViewCellStyle cellStyle,
TypeConverter formattedValueTypeConverter,
TypeConverter valueTypeConverter)
{
object ret = null;
ret = base.ParseFormattedValue(formattedValue, cellStyle,
formattedValueTypeConverter, valueTypeConverter);
if (ret != null && ret != DBNull.Value)
{
ret = FixDecimalPlaces(ret, cellStyle);
}
return ret;
}
Where FixDecimalPlaces is a function that rounds or truncates the cell value based on the specific column. This also let us show a truncated value in edit mode. Let’s assume the underlying value is 12.00000 (coming from a dataset, type decimal). The cell shows the formatted value 12.00 also entering in edit mode.
Using the Infragistics UltraGrid the value 12.00 becomes 12.00000 in edit mode. Is there a way to format the value in edit mode? We would not use masks if possible.
Best Regards,
Massimo Franzosi