'宣言 Public Overloads Function Clone() As UltraGridLayout
public UltraGridLayout Clone()
このメソッドを起動して、オブジェクトのコピーへの参照を返します。これはオブジェクトと等しい変数を設定することとは異なります。新しいコピーを作成することではありません。
このメソッドは、ひとつのオブジェクトを他の基本とする場合にも役立ちます。たとえば、複数のプロパティの例外はあるが、ひとつの Appearance オブジェクトを他と同じにしたい場合、既存の Appearance オブジェクトのクローンを作成して、コピーに変更を行い、オブジェクトの外観を変更するために使用することができます。
Imports Infragistics.Shared Imports Infragistics.Win Imports Infragistics.Win.UltraWinGrid Private toggleFlag As Boolean = False Private layout1 As UltraGridLayout = Nothing Private layout2 As UltraGridLayout = Nothing Private Sub Button9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button9.Click If Me.layout1 Is Nothing Or Me.layout2 Is Nothing Then Me.layout1 = Me.ultraGrid1.DisplayLayout ' Make a clone of layout1. Me.layout2 = layout1.Clone(PropertyCategories.All) ' Setup layout2. layout2.Override.CellAppearance.BackColor = Color.LightSkyBlue layout2.Bands(0).Columns(0).CellAppearance.BackColor = Color.Red End If ' Reset the layout since CopyFrom only copies properties that are set ' on the source layout. Me.ultraGrid1.DisplayLayout.Reset() If toggleFlag Then ' Copy the layout from layout1 Me.ultraGrid1.DisplayLayout.CopyFrom(layout1, PropertyCategories.All) Else ' Copy the layout from layout2 Me.ultraGrid1.DisplayLayout.CopyFrom(layout2, PropertyCategories.All) End If ' Toggle the flag. toggleFlag = Not toggleFlag End Sub
using Infragistics.Shared; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using System.Diagnostics; private bool toggleFlag = false; private UltraGridLayout layout1 = null; private UltraGridLayout layout2 = null; private void button9_Click(object sender, System.EventArgs e) { if ( null == this.layout1 || null == this.layout2 ) { this.layout1 = this.ultraGrid1.DisplayLayout; // Make a clone of layout1. this.layout2 = layout1.Clone( PropertyCategories.All ); // Setup layout2. layout2.Override.CellAppearance.BackColor = Color.LightSkyBlue; layout2.Bands[0].Columns[0].CellAppearance.BackColor = Color.Red; } // Reset the layout since CopyFrom only copies properties that are set // on the source layout. this.ultraGrid1.DisplayLayout.Reset( ); if ( toggleFlag ) { // Copy the layout from layout1 this.ultraGrid1.DisplayLayout.CopyFrom( layout1, PropertyCategories.All ); } else { // Copy the layout from layout2 this.ultraGrid1.DisplayLayout.CopyFrom( layout2, PropertyCategories.All ); } // Toggle the flag. toggleFlag = !toggleFlag; }