Add Bracket to "-" if value is negative & separator

Hi All,

I would like to add bracket to "-" if the value is negative & separator. I successfully do it on the "Gross:" field but not able to add it on values in the grid. Any idea how to do it?

  • 0

    Try something like this:

    Regex negativeValueRegex = new Regex(@"\-[0-9]*.[0-9]*");
    
    var grid = (Sage.ObjectStore.Controls.Grid)
        _form.FindControlByName("postedTransGrid").UnderlyingControl;
    
    grid.Format += (s, e) =>
    {
        if(negativeValueRegex.IsMatch( e.Value.ToString() ))
        {
            e.Cancel = true;
            e.Value = $"(-){e.Value.ToString().Substring(1)}";
        }
    };

  • 0 in reply to Chris Burke

    thank you that works..

    I just add few things to add separator

    Regex negativeValueRegex = new Regex(@"\-[0-9]*.[0-9]*");
    postedTransGrid.Format += (s, e) =>
    {
    decimal number;
    if (negativeValueRegex.IsMatch(e.Value.ToString()))
    {
    e.Cancel = true;
    e.Value = $"(-){Convert.ToDecimal(e.Value).ToString("N", new CultureInfo("en-US")).Substring(1)}";
    }
    else if(Decimal.TryParse(e.Value.ToString(), out number))
    {
    e.Cancel = true;
    e.Value = $"{Convert.ToDecimal(e.Value).ToString("N", new CultureInfo("en-US"))}";
    }
    };