GrapeCity MultiRow Windows Forms Documentation
EditingCellValueChanged Event
Example 


Occurs when the value of this editing cell has changed.
Syntax
Event EditingCellValueChanged As EventHandler
Dim instance As IEditingCell
Dim handler As EventHandler
 
AddHandler instance.EditingCellValueChanged, handler
event EventHandler EditingCellValueChanged
Remarks
The owner GcMultiRow listens to this event. If the user changes the value of the editing cell, the editing cell should fire this event to notify GcMultiRow; otherwise, the GcMultiRow control never knows the editing cell has been edited by the user and the value of the editing cell is not saved. The GcMultiRow.NotifyCurrentCellDirty method can be used instead of this event to notify the control of the value change.
Example
The following code example shows how to use this event to customize an editable cell. This code example is part of a larger example provided for the IEditingCell interface.
public object EditingCellFormattedValue
        {
            get
            {
                return _editingValue;
            }
            set
            {
                if ((int)value < this.Minimum)
                {
                    value = Minimum;
                }
                else if ((int)value > this.Maximum)
                {
                    value = Maximum;
                }

                if (_editingValue != (int)value)
                {
                    _editingValue = (int)value;

                    // When changing the editing cell's value, the cell should fire EditingCellValueChanged event to 
notify MultiRow control.
                    // When leaving edit mode, MultiRow uses this value as cell's new value.
                    this.OnEditingCellValueChanged(EventArgs.Empty);

                    // Notify MultiRow control to redraw this cell.
                    this.Invalidate();
                }
            }
        }

        public event EventHandler EditingCellValueChanged;
        protected virtual void OnEditingCellValueChanged(EventArgs e)
        {
            if (this.EditingCellValueChanged != null)
            {
                this.EditingCellValueChanged(this, e);
            }
        }

        protected override void OnCellFormatting(CellFormattingEventArgs e)
        {
            // When multiRow repaints cell, the cell gets the paint value.
            // The cell should use the EditingCellFormattedValue property value to paint the cell, if the cell is in edit 
mode.
            // Change the override OnPaint method to customize the cell painting logic for edit status, 
            // if so, overriding OnCellFormatting is not necessary.
            if (this.GcMultiRow.IsCurrentCellInEditMode &&
                this.GcMultiRow.CurrentCell.RowIndex == e.RowIndex && this.GcMultiRow.CurrentCell.CellIndex == 
e.CellIndex)
            {
                e.Value = this.EditingCellFormattedValue;
            }
            base.OnCellFormatting(e);
        }
Public Property EditingCellFormattedValue() As Object Implements IEditingCell.EditingCellFormattedValue
        Get
            Return _editingValue
        End Get
        Set(ByVal value As Object)
            If DirectCast(value, Integer) < Me.Minimum Then
                value = Minimum
            ElseIf DirectCast(value, Integer) > Me.Maximum Then
                value = Maximum
            End If

            If _editingValue <> DirectCast(value, Integer) Then
                _editingValue = DirectCast(value, Integer)

                ' When changing the editing cell's value, the cell should fire the EditingCellValueChanged event to 
notify the MultiRow control.
                ' When leaving edit mode, MultiRow uses this value as the cell's new value.
                Me.OnEditingCellValueChanged(EventArgs.Empty)

                ' Notify MultiRow control redraw this cell.
                Me.Invalidate()
            End If
        End Set
    End Property

    Public Event EditingCellValueChanged As EventHandler Implements IEditingCell.EditingCellValueChanged

    Protected Overridable Sub OnEditingCellValueChanged(ByVal e As EventArgs)
        RaiseEvent EditingCellValueChanged(Me, e)
    End Sub

    Protected Overloads Overrides Sub OnCellFormatting(ByVal e As CellFormattingEventArgs)
        ' When multiRow repaints the cell, the cell gets the paint value.
        ' The cell should use the EditingCellFormattedValue property value to paint the cell, if the cell is in edit 
mode.
        ' You can override the OnPaint method to customize the cell painting logic for edit mode.
        ' If so, overriding OnCellFormatting is not necessary.
        If Me.GcMultiRow.IsCurrentCellInEditMode AndAlso Me.GcMultiRow.CurrentCell.RowIndex = e.RowIndex 
AndAlso Me.GcMultiRow.CurrentCell.CellIndex = e.CellIndex Then
            e.Value = Me.EditingCellFormattedValue
        End If
        MyBase.OnCellFormatting(e)
    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

IEditingCell Interface
IEditingCell Members

 

 


Copyright © GrapeCity, inc. All rights reserved.