How to use C1.Win.C1FlexGrid.Classic.CellPropertySettings.flexcpFloodPercent

Posted by: van-thien on 28 November 2023, 11:35 am EST

  • Posted 28 November 2023, 11:35 am EST

    I would like to set color following the percentages

    [code]Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim i As Long

        Dim max As Double
        ' initialize array with random data
        Dim count(1, 7) As Single
        For i = 0 To 7
            count(0, i) = Rnd() * 100
            count(1, i) = Rnd() * 100
        Next
        ' initialize control
        fg.Cols = 3
        fg.Rows = 9
        fg.Cell(flexcpText, 0, 0) = "Age Range"
        fg.Cell(flexcpText, 0, 1) = "Females"
        fg.Cell(flexcpText, 0, 2) = "Males"
        ' make data bold
        fg.Cell(flexcpFontBold, 1, 1, fg.Rows - 1, fg.Cols - 1) = True
        ' place text in cells, keep track of maximum
        For i = 0 To 7
            fg.Cell(flexcpText, i + 1, 0) = 10 * i & " - " & (10 * (i + 1) - 1)
            fg.Cell(flexcpText, i + 1, 1) = count(0, i)
            fg.Cell(flexcpText, i + 1, 2) = count(1, i)
            If count(0, i) > max Then max = count(0, i)
            If count(1, i) > max Then max = count(1, i)
        Next
        ' set each cell's flood percentage,
        ' using max to scale from 0 to -100 for column 1
        ' and from 0 to 100 for column 2:
        For i = 0 To 7
            fg.Cell(flexcpFloodPercent, i + 1, 1) = -100 * count(0, i) / max
            fg.Cell(flexcpFloodPercent, i + 1, 1) = -100 * count(0, i) / max
            fg.Cell(flexcpFloodPercent, i + 1, 2) = 100 * count(1, i) / max
            fg.Cell(flexcpFloodColor, i + 1, 1) = Color.Red
            fg.Cell(flexcpFloodColor, i + 1, 1) = Color.Yellow
            fg.Cell(flexcpFloodColor, i + 1, 2) = Color.Aqua
        Next
    End Sub[/code]
    

    This is my result

  • Posted 29 November 2023, 8:13 am EST

    Hello,

    We regret any inconvenience caused. The C1FlexGridClassic serves as a wrapper class for C1FlexGrid, designed to facilitate a seamless transition from VSFlexGrid to C1FlexGrid.

    Given that C1FlexGridClassic functions as a wrapper, if a particular function is absent in FlexGrid, it will similarly be absent in C1FlexGridClassic. Since the functionality you’re attempting to implement is not inherent in FlexGrid, you will need to implement it customarily using the OwnerDraw event. Here’s how you can proceed:

    Sub FG_OwnerDraw(sender As Object, e As OwnerDrawCellEventArgs) Handles fg.OwnerDrawCell
        If e.Measuring Then Return
        Dim val As Double
        If Double.TryParse(fg.Cell(CellPropertySettings.flexcpText, e.Row, e.Col), val) Then
            'configuring the bar
            Dim rc = e.Bounds
            Dim originalWidth = rc.Width
            rc.Width *= (val / Max)
    
            'draw background
            e.DrawCell(DrawCellFlags.Background)
            e.DrawCell(DrawCellFlags.Border)
    
            'if Flood percent is negative shift the bar to right hand side
            If e.Col = 1 Then
                rc.X += originalWidth - rc.Width
            End If
    
            rc.Inflate(-1, -1)
            e.Graphics.FillRectangle(IIf(e.Col = 1, Brushes.Red, Brushes.Aqua), rc)
    
            'draw cell content
            e.DrawCell(DrawCellFlags.Content)
        End If
    End Sub

    Please refer to the attached sample for implementation. (see FlexGridClassic48_FloodPercent_VB.zip)

    Regards,

    Uttkarsh.

Need extra support?

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

Learn More

Forum Channels