PowerTools MultiRow for Windows Forms 8.0J
EditingCellFormattedValue プロパティ (IEditingCell)
使用例 

セルの書式設定された値を取得または設定します。
構文
Property EditingCellFormattedValue As Object
object EditingCellFormattedValue {get; set;}

プロパティ値

セルの値を表すSystem.Object
解説
IEditingCellインタフェースを実装しているセルが編集状態にある場合、ユーザーがUI操作(マウスまたはキーボード)によってセルの値を編集すると、このプロパティの値がセルに表示されます。このとき、セルのCell.Valueプロパティは変更されず、EditingCellFormattedValueプロパティのみが変更されます。ユーザーが編集状態を終了して編集値をコミットすると、EditingCellFormattedValueが基になる値に保存されます。
使用例
次のサンプルコードは、このプロパティを使用して編集可能セルをカスタマイズする方法を示します。このサンプルコードは、IEditingCellインタフェースに示されている詳細なコード例の一部を抜粋したものです。
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 change the editing cell's value, the cell should fire EditingCellValueChanged event to notify MultiRow control.
            // So that, when leave editing status, MultiRow control can use this value as cell's new value.
            this.OnEditingCellValueChanged(EventArgs.Empty);

            // Notify MultiRow control 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 control repaint cell, the cell will get the paint value.
    // The cell should use the EditingCellFormattedValue property value to paint cell, if cell in editing status.
    // You also change override OnPaint method to customize the cell painting logic for edit status, 
    // if so, override 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 change the editing cell's value, the cell should fire EditingCellValueChanged event to notify MultiRow control.
            ' So that, when leave editing status, MultiRow control can use this value as 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 control repaint cell, the cell will get the paint value.
    ' The cell should use the EditingCellFormattedValue property value to paint cell, if cell in editing status.
    ' You also change override OnPaint method to customize the cell painting logic for edit status, 
    ' if so, override 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
参照

IEditingCell インターフェース
IEditingCell メンバ

 

 


© 2008-2015 GrapeCity inc. All rights reserved.