Red color negative value

Posted by: cvetx on 8 September 2017, 2:17 pm EST

  • Posted 8 September 2017, 2:17 pm EST

    Let's say I have a table like below.


     Emp_ID    Payment_amount
        101          $1000
        201         -$250


    Is there any way to make it "RED" color for -$250" on spread sheet when the data is retrived thru dataset?


    Thanks.

  • Replied 8 September 2017, 2:17 pm EST

    cvetx,


    One option is to use conditional formats.  For example...


        NamedStyle style = new NamedStyle();
        style.ForeColor = Color.Red;


        fpSpread1.Sheets[0].SetConditionalFormat(-1, 1, style, ComparisonOperator.LessThan, "0");


    Another option is to use the NegativeRed property on the cell types that support numbers (e.g. GeneralCellType, NumberCellType, CurrencyCellType, PercentCellType).  For example...


        FarPoint.Win.Spread.CellType.NumberCellType cellType = new FarPoint.Win.Spread.CellType.NumberCellType();
        cellType.NegativeRed = true;


        fpSpread1.Sheets[0].Columns[1].CellType = cellType;

  • Replied 8 September 2017, 2:17 pm EST

    Thanks.


     Is it possible to find Max or Min value on a colum and return the roe and column value? Then I can color it as red.


     

  • Replied 8 September 2017, 2:17 pm EST

    Hello,

    I don't find a direct way to find minimum/maximum value which can give you Row/ Column Index.However you may use the formula property of Spread  to find the minimum/maximum value and later you may apply conditional formatting to found value.

    Have a look at the below code snippet.Which finds the minimum and maximum value and change the fore color of the text in that cell.

     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load     
            FpSpread1.ActiveSheet.Cells(0, 0).Value = 14
            FpSpread1.ActiveSheet.Cells(1, 0).Value = 13
            FpSpread1.ActiveSheet.Cells(2, 0).Value = 12
            FpSpread1.ActiveSheet.Cells(3, 0).Value = 1
            FpSpread1.ActiveSheet.Cells(4, 0).Value = 15
            FpSpread1.ActiveSheet.Cells(5, 0).Value = 123
            FpSpread1.ActiveSheet.Cells(6, 0).Value = 19
            FpSpread1.ActiveSheet.Cells(7, 0).Value = 118
            FpSpread1.ActiveSheet.Cells(8, 0).Value = 11
            FpSpread1.ActiveSheet.Cells(9, 0).Value = 120

            FpSpread1.Sheets(0).Cells(1, 1).Formula = "MIN(A1:A10)"
            FpSpread1.Sheets(0).Cells(2, 2).Formula = "MAX(A1:A10)"
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim style As New FarPoint.Win.Spread.NamedStyle
            style.ForeColor = Color.Brown
            FpSpread1.Sheets(0).SetConditionalFormat(-1, 0, style, FarPoint.Win.Spread.ComparisonOperator.EqualTo, FpSpread1.Sheets(0).GetValue(1, 1))
            FpSpread1.Sheets(0).SetConditionalFormat(-1, 0, style, FarPoint.Win.Spread.ComparisonOperator.EqualTo, FpSpread1.Sheets(0).GetValue(2, 2))
        End Sub

     I hope it will help you.

    Thanks,

     

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels