GrapeCity MultiRow Windows Forms Documentation
DynamicCellStyleConditionHandler Delegate
ExampleExample 


A DynamicCellStyleContext value that indicates the current context of GcMultiRow.
Represents a method that returns a CellStyle with the specified DynamicCellStyleContext.
Syntax
Public Delegate Function DynamicCellStyleConditionHandler( _
   ByVal context As DynamicCellStyleContext _
) As CellStyle
Dim instance As New DynamicCellStyleConditionHandler(AddressOf HandlerMethod)
public delegate CellStyle DynamicCellStyleConditionHandler( 
   DynamicCellStyleContext context
)

Parameters

context
A DynamicCellStyleContext value that indicates the current context of GcMultiRow.
Remarks
The DynamicCellStyle class defines a DynamicCellStyle.ConditionHandler which is a DynamicCellStyleConditionHandler type. This allows you to attach an event handling method, that can return a CellStyle with the given context dynamically.
Example
The following code example shows how to implement the "NewRowDefaultCellStyle". You can set a DynamicCellStyle to Row.DefaultCellStyle, and return a CellStyle object when the painted row is a new row. This code example is part of a larger example provided for the DynamicCellStyle class.
private void Form1_Load(object sender, EventArgs e)
        {

            Template template1 = Template.CreateGridTemplate(7);

            DynamicCellStyle dynamicCellStyle1 = new DynamicCellStyle();
            dynamicCellStyle1.ConditionHandler += new DynamicCellStyleConditionHandler(GetNewRowDefaultCellStyle);

            template1.Row.DefaultCellStyle = dynamicCellStyle1;

            gcMultiRow1.Template = template1;
            gcMultiRow1.RowCount = 10;
        }

        public CellStyle GetNewRowDefaultCellStyle(DynamicCellStyleContext context)
        {
            CellStyle newRowDefaultCellStyle = new CellStyle();

            // If all the cell values in a specific row are empty, the cell's backcolor is white, otherwise backcolor is yellow.
            newRowDefaultCellStyle.BackColor = Color.White;
            if (context.CellScope == CellScope.Row)
            {
                for (int i = 0; i < context.GcMultiRow.Rows[context.RowIndex].Cells.Count; i++)
                {
                    object value = context.GcMultiRow.Rows[context.RowIndex][i].Value;

                    if (value != null)
                    {
                        newRowDefaultCellStyle.BackColor = Color.Yellow;
                        break;
                    }
                }
            }
            
            return newRowDefaultCellStyle;
        }
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim template1 As Template = Template.CreateGridTemplate(7)

        Dim dynamicCellStyle1 As New DynamicCellStyle()
        dynamicCellStyle1.ConditionHandler = AddressOf Me.GetNewRowDefaultCellStyle

        template1.Row.DefaultCellStyle = dynamicCellStyle1

        gcMultiRow1.Template = template1
        gcMultiRow1.RowCount = 10
    End Sub

    Public Function GetNewRowDefaultCellStyle(ByVal context As DynamicCellStyleContext) As CellStyle
        Dim newRowDefaultCellStyle As New CellStyle()

        ' If all the cell values in a specific row are empty, the cell's backcolor is white, otherwise backcolor is yellow.
        newRowDefaultCellStyle.BackColor = Color.White
        If context.CellScope = CellScope.Row Then

            For i As Integer = 0 To context.GcMultiRow.Rows(context.RowIndex).Cells.Count - 1
                Dim value As Object = context.GcMultiRow.Rows(context.RowIndex)(i).Value
                If value <> Nothing Then
                    newRowDefaultCellStyle.BackColor = Color.Yellow
                    Exit For
                End If
            Next
        End If
        Return newRowDefaultCellStyle
    End Function
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

DynamicCellStyleConditionHandler Members
GrapeCity.Win.MultiRow Namespace
CellStyle Class
DynamicCellStyle Class

 

 


Copyright © GrapeCity, inc. All rights reserved.