GrapeCity MultiRow Windows Forms Documentation
FormattedValue Property (CellPaintingEventArgs)
Example 


Gets the formatted value of the current cell.
Syntax
Public ReadOnly Property FormattedValue As Object
Dim instance As CellPaintingEventArgs
Dim value As Object
 
value = instance.FormattedValue
public object FormattedValue {get;}

Property Value

An System.Object that represents the formatted value of the current cell.
Example
The following code example shows how to customize a cell's paint logic. This code example is part of a larger example provided for the GcMultiRow.CellPainting event.
void gcMultiRow_CellPainting(object sender, CellPaintingEventArgs e)
        {
            if (e.CellIndex == 1 && e.Scope == CellScope.Row)
            {
                e.PaintBackground(e.ClipBounds);

                PaintRateBlock(e);

                e.PaintForeground(e.ClipBounds);

                e.PaintBorder(e.ClipBounds);

                // If you customize the paint logic, make sure the Handled property is set to true.
                e.Handled = true;
            }
        }
        private static void PaintRateBlock(CellPaintingEventArgs e)
        {
            Color color1 = Color.Red;
            Color color2 = Color.Orange;
            if (e.Selected)
            {
                color1 = Color.Blue;
                color2 = Color.SkyBlue;
            }

            decimal rate = 0m;

            if (e.Value != null)
            {
                rate = (decimal)(e.Value) / 100m;
            }

            // Calculate block size.
            int spinButtonWidth = 17;
            int blockWidth = (int)((e.ClipBounds.Width - spinButtonWidth) * rate);

            if (blockWidth > 0)
            {
                Rectangle rect = e.CellBounds;

                rect.Width = blockWidth;

                LinearGradientBrush brush = new LinearGradientBrush(rect, color1, color2, LinearGradientMode.Vertical);

                e.Graphics.FillRectangle(brush, rect);
            }
        }
Private Sub gcMultiRow_CellPainting(ByVal sender As Object, ByVal e As CellPaintingEventArgs) Handles gcMultiRow.CellPainting
        If e.CellIndex = 1 AndAlso e.Scope = CellScope.Row Then
            e.PaintBackground(e.ClipBounds)

            PaintRateBlock(e)

            e.PaintForeground(e.ClipBounds)

            e.PaintBorder(e.ClipBounds)

            ' If you customize the paint logic, make sure the Handled property is set to true.
            e.Handled = True
        End If
    End Sub
    Private Shared Sub PaintRateBlock(ByVal e As CellPaintingEventArgs)
        Dim color1 As Color = Color.Red
        Dim color2 As Color = Color.Orange
        If e.Selected Then
            color1 = Color.Blue
            color2 = Color.SkyBlue
        End If

        Dim rate As Decimal = 0D

        If e.Value <> Nothing Then
            rate = DirectCast((e.Value), Decimal) / 100D
        End If

        ' Calculate block size.
        Dim spinButtonWidth As Integer = 17
        Dim blockWidth As Integer = CInt((e.ClipBounds.Width - spinButtonWidth) * rate)

        If blockWidth > 0 Then
            Dim rect As Rectangle = e.CellBounds

            rect.Width = blockWidth

            Dim brush As New LinearGradientBrush(rect, color1, color2, LinearGradientMode.Vertical)

            e.Graphics.FillRectangle(brush, rect)
        End If
    End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CellPaintingEventArgs Class
CellPaintingEventArgs Members

 

 


Copyright © GrapeCity, inc. All rights reserved.