PowerTools MultiRow for Windows Forms 8.0J
Clone メソッド (Cell)
使用例 

このセルの同一コピーを作成します。
構文
Public Overridable Function Clone() As Object
public virtual object Clone()

戻り値の型

クローンされたCellを表すSystem.Object値。
解説

このメソッドは、このCellNameプロパティをコピーしません。NameプロパティはTemplate内でのCellの一意の識別子なので、このプロパティをクローンするのは適切ではありません。

Cellクラスの派生クラスを作成してそのクラスに新しいプロパティを追加する場合は、必ずCloneメソッドをオーバーライドしてください。

継承時の注意:

派生クラスでCloneメソッドをオーバーライドする場合は、基本クラスのCloneメソッドを呼び出して、基本クラスのプロパティが新しいセルにコピーされるようにしてください。また、派生クラスに追加したすべてのプロパティの値も必ずコピーしてください。

使用例
次のサンプルコードは、カスタムセルでこのメソッドを使用する方法を示します。このサンプルコードは、IEditingControlクラスに示されている詳細なコード例の一部を抜粋したものです。
public class ListBoxCell : Cell
{
    public override Type EditType
    {
        get
        {
            return typeof(ListBoxEditingControl);
        }
    }

    List<string> _items = new List<string>();

    public List<string> Items
    {
        get
        {
            return _items;
        }
    }

    protected override void InitializeEditingControl(int rowIndex, object formattedValue, CellStyle style)
    {
        // Apply the settings of cell to editing control. 
        base.InitializeEditingControl(rowIndex, formattedValue, style);

        ListBoxEditingControl listBoxEditingControl = this.GcMultiRow.EditingControl as ListBoxEditingControl;

        for (int i = 0; i < this._items.Count; i++)
        {
            listBoxEditingControl.Items.Add(this._items[i]);
        }

        listBoxEditingControl.FormattedValue = formattedValue;
    }

    protected override void TerminateEditingControl(int rowIndex)
    {
        ListBoxEditingControl listBoxEditingControl = this.GcMultiRow.EditingControl as ListBoxEditingControl;
        
        // For performance reason, MultiRow use same instance for all cells.
        // So, when leave editing status, you should clear items, to prepare editing control be used next time.
        listBoxEditingControl.Items.Clear();

        base.TerminateEditingControl(rowIndex);
    }

    public override object Clone()
    {
        // When you derive from Cell and add new properties to the derived class, be sure to
        // override the Clone method to copy the new properties during cloning operations. 
        // You should also call the base class's Clone method so that the properties of the 
        // base class are copied to the new cell. 
        ListBoxCell listBoxCell = base.Clone() as ListBoxCell;

        listBoxCell.Items.AddRange(this.Items);

        return listBoxCell;
    }
}
Public Class ListBoxCell
    Inherits Cell
    Public Overloads Overrides ReadOnly Property EditType() As Type
        Get
            Return GetType(ListBoxEditingControl)
        End Get
    End Property

    Private _items As New List(Of String)()

    Public ReadOnly Property Items() As List(Of String)
        Get
            Return _items
        End Get
    End Property

    Protected Overloads Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal formattedValue As Object, ByVal style As CellStyle)
        ' Apply the settings of cell to editing control. 
        MyBase.InitializeEditingControl(rowIndex, formattedValue, style)

        Dim listBoxEditingControl As ListBoxEditingControl = TryCast(Me.GcMultiRow.EditingControl, ListBoxEditingControl)

        For i As Integer = 0 To Me._items.Count - 1
            listBoxEditingControl.Items.Add(Me._items(i))
        Next

        listBoxEditingControl.FormattedValue = formattedValue
    End Sub

    Protected Overloads Overrides Sub TerminateEditingControl(ByVal rowIndex As Integer)
        Dim listBoxEditingControl As ListBoxEditingControl = TryCast(Me.GcMultiRow.EditingControl, ListBoxEditingControl)

        ' For performance reason, MultiRow use same instance for all cells.
        ' So, when leave editing status, you should clear items, to prepare editing control be used next time.
        listBoxEditingControl.Items.Clear()

        MyBase.TerminateEditingControl(rowIndex)
    End Sub

    Public Overloads Overrides Function Clone() As Object
        ' When you derive from Cell and add new properties to the derived class, be sure to
        ' override the Clone method to copy the new properties during cloning operations. 
        ' You should also call the base class's Clone method so that the properties of the 
        ' base class are copied to the new cell. 
        Dim listBoxCell As ListBoxCell = TryCast(MyBase.Clone(), ListBoxCell)

        listBoxCell.Items.AddRange(Me.Items)

        Return listBoxCell
    End Function
End Class
参照

Cell クラス
Cell メンバ

 

 


© 2008-2015 GrapeCity inc. All rights reserved.