I have a string column in my ultrawingrid, which contains integer data. I need to use thousand separator on that column. But, when I used format property, I realized it does not work on a string column.
Does someone have any idea how to do that?
You need to associate a IDataFilter derived class to the Editor.DataFilter property of your column. Suppose for example you have a bound column named 'NumberCode' of type string, put this code in the InitializeLayout event of your grid
UltraGridColum cl = e.DisplayLayout.Bands[0].Columns["NumberCode"];
cl.Editor.DataFilter = new ThousandSeparator();
and then create a simple class that implements the interface IDataFilter like this:
public class ThousandFormatter : IEditorDataFilter
{
public ThousandFormatter()
{ }
public object Convert(EditorDataFilterConvertArgs conversionArgs)
{
if (conversionArgs.Direction == ConversionDirection.OwnerToEditor)
{
UltraGridCell cell = conversionArgs.Context as UltraGridCell;
if (cell != null && cell.Column.Key == "NumberCode")
{
conversionArgs.Handled = true;
decimal dValue = System.Convert.ToDecimal(conversionArgs.Value);
return dValue.ToString("#,##0");
}
}
return conversionArgs.Value;
}
}