バージョン

Appearance プロパティ (UltraGridCell)

オブジェクトのフォーマットを制御するAppearanceオブジェクトを設定します。
シンタックス
'宣言
 
Public Property Appearance As Infragistics.Win.Appearance
public Infragistics.Win.Appearance Appearance {get; set;}
解説

オブジェクトの Appearance プロパティを使用して、外観を決定する Appearance オブジェクトにオブジェクトを関連付けます。Appearance オブジェクトには、色、境界線、フォント、透明度などの設定を制御するプロパティがあります。UltraWinGrid のオブジェクトでは、ほとんどの場合、書式関連のプロパティを直接設定しません。その代わりに Appearance オブジェクトのプロパティを設定することで、その Appearance オブジェクトが関連付けられているオブジェクトの書式設定を制御します。

Appearance プロパティを使用して Appearance オブジェクトの属性を他のオブジェクトに割り当てるには、2 つの方法があります。1つは、新しい Appearance オブジェクトを作成し、それを Appearances コレクションに直接追加します。これで新しい Appearance オブジェクトを、書式設定したいオブジェクトの Appearance プロパティに割り当てます。この方法では、事前に明示的に作成してプロパティの設定を割り当てなければならない「名前付き」Appearance オブジェクトを使用します。たとえば、グリッドの Appearances コレクション内にオブジェクトを作成して値を割り当てるには、次のように記述します。

UltraWinGrid1.Appearances.Add "New1"

UltraWinGrid1.Appearances("New1").BorderColor = System.Drawing.Color.Blue

UltraWinGrid1.Appearances("New1").ForeColor = System.Drawing.Color.Red

この方法でオブジェクトを作成すると、グリッドの表示部分に書式は適用されません。オブジェクトはプロパティ値が設定された状態でコレクション内に存在するだけであり、使用されるまで待機しています。実際にこのオブジェクトを使用するには、グリッド (または別のオブジェクト) の Appearance プロパティにそのオブジェクトを割り当てる必要があります。

UltraWinGrid1.Appearance = UltraWinGrid1.Appearances("New1")

この場合、存在している Appearance オブジェクトは 1 つだけです。グリッドの外観は、コレクション内の「New1」オブジェクトの設定によって決まります。コレクション内のオブジェクトに変更を加えると、その変更は即時にグリッドに反映されます。

Appearanceプロパティのもう 1 つの使用方法は、Appearanceプロパティに直接プロパティ値を設定する方法です。次に例を示します。

UltraWinGrid1.Appearance.ForeColor = System.Drawing.Color.Blue

この場合は、コントロールによって自動的に Appearance オブジェクトが作成されます。この Appearance オブジェクトは Appearances コレクションのメンバーではなく、名前はありません。このオブジェクトは、作成対象のオブジェクトに固有の「組み込み」Appearanceオブジェクトです。組み込み Appearance オブジェクトのプロパティを変更すると、それが属するオブジェクト内でのみ、その変更が反映されます。

従属関係を作成せずに、名前付き Appearance オブジェクトのプロパティを組み込み Appearance オブジェクトに割り当てることができます。たとえば、次のようなコードがあるとします。

UltraWinGrid1.Appearance.ForeColor = UltraWinGrid1.Appearances("New1").ForeColor

この例では、組み込みオブジェクトの前景色と名前付きオブジェクトの前景色の間に関係は 確立されません 。これは単に名前付きオブジェクトの値を組み込みオブジェクトの値に1回限りで割り当てているだけです。この場合は 2 つの Appearance オブジェクトが存在し (1 つはコレクション内にあり、もう 1 つはグリッドに関連付けられています) 、互いに独立して動作します。

従属関係を作成せずに名前付きオブジェクトのすべてのプロパティを組み込みオブジェクトに一度に割り当てる場合、Appearance オブジェクトの Clone メソッドを使用して設定を複製し、それを適用することができます。名前付き Appearance オブジェクト「New1」のすべてのプロパティ設定をグリッドの組み込み Appearance オブジェクトに適用する場合で、「New1」への変更をグリッドに自動的に反映したくないときは、次のコードを使用します。

UltraWinGrid1.Appearance = UltraWinGrid1.Appearances("New1").Clone

Appearance オブジェクトのプロパティは、階層式に適用することも可能です。プロパティの中には「use default」値に設定できるものがあります。 これは、オブジェクトの親からプロパティの設定を取得することを意味します。この機能はデフォルトで有効になっているため、設定を変更しないかぎり、子オブジェクトは親に類似し、グリッドの上位階層で設定された書式は下位のオブジェクトに引き継がれます。

使用例
Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

  Private Sub Button9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button9.Click

      ' Get the layout, a band, a column, a row and a cell for the demonstration purpose.
      Dim layout As UltraGridLayout = Me.ultraGrid1.DisplayLayout
      Dim band As UltraGridBand = layout.Bands(0)
      Dim column As UltraGridColumn = band.Columns(0)
      Dim row As UltraGridRow = Me.ultraGrid1.Rows(0)
      Dim cell As UltraGridCell = row.Cells(column)

      ' The way the UltraGrid resolves cell appearance is that objects at a lower level
      ' in the object model hierarchy have higher precedence than objects in higher level.
      ' For example, a cell has a higher precedence than its row. A row has a higher
      ' precedence than a column. The precedence order usually is cell, row, column, band,
      ' layout in decresing precedence order.

      ' Set grid-wide cell appearance by using the layout's Override.
      layout.Override.CellAppearance.BackColor = Color.Yellow

      ' You can override above settings for a a band by setting the 
      ' Override.CellAppearance on the band. This will have higher precedence than
      ' the layout.Override.
      band.Override.CellAppearance.BackColor = Color.Magenta

      ' You can override cell appearance on a column as well so cell-appearance settings
      ' on both the band and the layout will be ignored.
      column.CellAppearance.BackColor = Color.Red

      ' In the same manner, you can override cell-apperance for a row.
      row.CellAppearance.BackColor = Color.Green

      ' You can override the cell-appearance for individual cells.
      cell.Appearance.BackColor = Color.Blue

  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void button9_Click(object sender, System.EventArgs e)
{

	// Get the layout, a band, a column, a row and a cell for the demonstration purpose.
	UltraGridLayout layout = this.ultraGrid1.DisplayLayout;
	UltraGridBand   band   = layout.Bands[0];
	UltraGridColumn column = band.Columns[0];
	UltraGridRow    row    = this.ultraGrid1.Rows[0];
	UltraGridCell    cell   = row.Cells[column];

	// The way the UltraGrid resolves cell appearance is that objects at a lower level
	// in the object model hierarchy have higher precedence than objects in higher level.
	// For example, a cell has a higher precedence than its row. A row has a higher
	// precedence than a column. The precedence order usually is cell, row, column, band,
	// layout in decresing precedence order.

	// Set grid-wide cell appearance by using the layout's Override.
	layout.Override.CellAppearance.BackColor = Color.Yellow;

	// You can override above settings for a a band by setting the 
	// Override.CellAppearance on the band. This will have higher precedence than
	// the layout.Override.
	band.Override.CellAppearance.BackColor = Color.Magenta;

	// You can override cell appearance on a column as well so cell-appearance settings
	// on both the band and the layout will be ignored.
	column.CellAppearance.BackColor = Color.Red;

	// In the same manner, you can override cell-apperance for a row.
	row.CellAppearance.BackColor = Color.Green;

	// You can override the cell-appearance for individual cells.
	cell.Appearance.BackColor = Color.Blue;

}
参照