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

このコントロールによって編集される行のインデックスを取得または設定します。
構文
Property RowIndex As Integer
int RowIndex {get; set;}

プロパティ値

編集コントロールのオーナーセルの行のインデックスを表すSystem.Int32値。編集コントロールがGcMultiRowにインストールされていない場合、このプロパティは常に-1を返します。
使用例
次のサンプルコードは、カスタム編集コントロールでこのプロパティを使用する方法を示します。このサンプルコードは、IEditingControlクラスに示されている詳細なコード例の一部を抜粋したものです。
public class ListBoxEditingControl : ListBox, IEditingControl
{
    public ListBoxEditingControl()
    {
        this.BorderStyle = BorderStyle.None;
    }

    private GcMultiRow _gcMultiRow;

    // MultiRow control will set this property when begin edit. Editing control can use this property.
    public GcMultiRow GcMultiRow
    {
        get
        {
            return _gcMultiRow;
        }
        set
        {
            _gcMultiRow = value;
        }
    }

    private int _rowIndex;

    // MultiRow control will set this property when begin edit. Editing control can use this property.
    public int RowIndex
    {
        get
        {
            return _rowIndex;
        }
        set
        {
            _rowIndex = value;
        }
    }

    // 1. When begin edit, MultiRow should initial this property.
    // 2. When end edit, MultiRow will use this property's value as cell value.
    public object FormattedValue
    {
        get
        {
            return this.Text;
        }
        set
        {
            if (value == null)
            {
                this.Text = string.Empty;
            }
            else
            {
                this.Text = value.ToString();
            }
        }
    }
    
    // When user press Ctrl and wheel mouse wheel button. MultiRow will be zoomed.
    // MultiRow will change this property's value when zoom.
    // EditingControl should do some thing to fit the new zoom factor, for example, change Font.
    private float _zoomFactor;
    private Font _initializeFont = null;
    public float ZoomFactor
    {
        get
        {
            return _zoomFactor;
        }
        set
        {
            this._zoomFactor = value;

            if (_zoomFactor != 1 && _initializeFont != null)
            {
                this.Font = new Font(_initializeFont.FontFamily, _initializeFont.Size * _zoomFactor);
            }
        }
    }

    public Cursor EditingPanelCursor
    {
        get 
        {
            return Cursors.Default;
        }
    }

    // The keys which will be handle by editing control.
    public bool WantsInputKey(Keys keyData)
    {
        // The editing control will handle up and down keys.
        if (keyData == Keys.Up || keyData == Keys.Down)
        {
            return true;
        }
        return false;
    }

    public void PrepareEditingControlForEdit(bool selectAll)
    {
        // Do some thing to prepare edit for editing control.
    }

    // Apply style.
    public void ApplyCellStyleToEditingControl(CellStyle cellStyle)
    {
        this.BackColor = Color.FromArgb(255, cellStyle.BackColor);
        this.ForeColor = Color.FromArgb(255, cellStyle.ForeColor);

        _initializeFont = cellStyle.Font;

        if (this._zoomFactor != 1)
        {
            this.Font = new Font(_initializeFont.FontFamily, _initializeFont.Size * _zoomFactor);
        }
    }

    // When the value has been edited, editing control should fire DirtyStateChanged event to notify MultiRow control.
    protected override void OnSelectedIndexChanged(EventArgs e)
    {
        base.OnSelectedIndexChanged(e);

        this.OnDirtyStateChanged(EventArgs.Empty);
    }

    protected virtual void OnDirtyStateChanged(EventArgs e)
    {
        if (this.DirtyStateChanged != null)
        {
            this.DirtyStateChanged(this, e);
        }
    }

    public event EventHandler DirtyStateChanged;
}
Public Class ListBoxEditingControl
    Inherits ListBox
    Implements IEditingControl
    Public Sub New()
        Me.BorderStyle = BorderStyle.None
    End Sub

    Private _gcMultiRow As GcMultiRow

    ' MultiRow control will set this property when begin edit. Editing control can use this property.
    Public Property GcMultiRow() As GcMultiRow Implements IEditingControl.GcMultiRow
        Get
            Return _gcMultiRow
        End Get
        Set(ByVal value As GcMultiRow)
            _gcMultiRow = value
        End Set
    End Property

    Private _rowIndex As Integer

    ' MultiRow control will set this property when begin edit. Editing control can use this property.
    Public Property RowIndex() As Integer Implements IEditingControl.RowIndex
        Get
            Return _rowIndex
        End Get
        Set(ByVal value As Integer)
            _rowIndex = value
        End Set
    End Property

    ' 1. When begin edit, MultiRow should initial this property.
    ' 2. When end edit, MultiRow will use this property's value as cell value.
    Public Property FormattedValue() As Object Implements IEditingControl.FormattedValue
        Get
            Return Me.Text
        End Get
        Set(ByVal value As Object)
            If value = Nothing Then
                Me.Text = String.Empty
            Else
                Me.Text = value.ToString()
            End If
        End Set
    End Property

    ' When user press Ctrl and wheel mouse wheel button. MultiRow will be zoomed.
    ' MultiRow will change this property's value when zoom.
    ' EditingControl should do some thing to fit the new zoom factor, for example, change Font.
    Private _zoomFactor As Single
    Private _initializeFont As Font = Nothing
    Public Property ZoomFactor() As Single Implements IEditingControl.ZoomFactor
        Get
            Return _zoomFactor
        End Get
        Set(ByVal value As Single)
            Me._zoomFactor = value

            If _zoomFactor <> 1 AndAlso Not _initializeFont Is Nothing Then
                Me.Font = New Font(_initializeFont.FontFamily, _initializeFont.Size * _zoomFactor)
            End If
        End Set
    End Property

    Public ReadOnly Property EditingPanelCursor() As Cursor Implements IEditingControl.EditingPanelCursor
        Get
            Return Cursors.Default
        End Get
    End Property

    ' The keys which will be handle by editing control.
    Public Function WantsInputKey(ByVal keyData As Keys) As Boolean Implements IEditingControl.WantsInputKey
        ' The editing control will handle up and down keys.
        If keyData = Keys.Up OrElse keyData = Keys.Down Then
            Return True
        End If
        Return False
    End Function

    Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements IEditingControl.PrepareEditingControlForEdit
        ' Do some thing to prepare edit for editing control.
    End Sub

    ' Apply style.
    Public Sub ApplyCellStyleToEditingControl(ByVal cellStyle As CellStyle) Implements IEditingControl.ApplyCellStyleToEditingControl
        Me.BackColor = Color.FromArgb(255, cellStyle.BackColor)
        Me.ForeColor = Color.FromArgb(255, cellStyle.ForeColor)

        _initializeFont = cellStyle.Font

        If Me._zoomFactor <> 1 Then
            Me.Font = New Font(_initializeFont.FontFamily, _initializeFont.Size * _zoomFactor)
        End If
    End Sub

    ' When the value has been edited, editing control should fire DirtyStateChanged event to notify MultiRow control.
    Protected Overloads Overrides Sub OnSelectedIndexChanged(ByVal e As EventArgs)
        MyBase.OnSelectedIndexChanged(e)

        Me.OnDirtyStateChanged(EventArgs.Empty)
    End Sub

    Protected Overridable Sub OnDirtyStateChanged(ByVal e As EventArgs)
        RaiseEvent DirtyStateChanged(Me, e)
    End Sub

    Public Event DirtyStateChanged As EventHandler Implements IEditingControl.DirtyStateChanged
End Class
参照

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

 

 


© 2008-2015 GrapeCity inc. All rights reserved.