GridTableStylesCollection クラス

定義

DataGridTableStyle コントロールに含まれる DataGrid オブジェクトのコレクションを表します。

public ref class GridTableStylesCollection : System::Windows::Forms::BaseCollection, System::Collections::IList
[System.ComponentModel.ListBindable(false)]
public class GridTableStylesCollection : System.Windows.Forms.BaseCollection, System.Collections.IList
[<System.ComponentModel.ListBindable(false)>]
type GridTableStylesCollection = class
    inherit BaseCollection
    interface IList
    interface ICollection
    interface IEnumerable
Public Class GridTableStylesCollection
Inherits BaseCollection
Implements IList
継承
GridTableStylesCollection
属性
実装

次のコード例では、2 つの DataGridTableStyle オブジェクトを作成し、 コントロールの GridTableStylesCollection プロパティによって返される に TableStyles それぞれを DataGrid 追加します。

void AddCustomDataTableStyle()
{
   DataGridTableStyle^ ts1 = gcnew DataGridTableStyle;
   ts1->MappingName = "Customers";
   
   // Set other properties.
   ts1->AlternatingBackColor = Color::LightGray;
   
   /* Add a GridColumnStyle and set its MappingName
     to the name of a DataColumn in the DataTable.
     Set the HeaderText and Width properties. */
   DataGridColumnStyle^ boolCol = gcnew DataGridBoolColumn;
   boolCol->MappingName = "Current";
   boolCol->HeaderText = "IsCurrent Customer";
   boolCol->Width = 150;
   ts1->GridColumnStyles->Add( boolCol );
   
   // Add a second column style.
   DataGridColumnStyle^ TextCol = gcnew DataGridTextBoxColumn;
   TextCol->MappingName = "custName";
   TextCol->HeaderText = "Customer Name";
   TextCol->Width = 250;
   ts1->GridColumnStyles->Add( TextCol );
   
   // Create the second table style with columns.
   DataGridTableStyle^ ts2 = gcnew DataGridTableStyle;
   ts2->MappingName = "Orders";
   
   // Set other properties.
   ts2->AlternatingBackColor = Color::LightBlue;
   
   // Create new ColumnStyle objects.
   DataGridColumnStyle^ cOrderDate = gcnew DataGridTextBoxColumn;
   cOrderDate->MappingName = "OrderDate";
   cOrderDate->HeaderText = "Order Date";
   cOrderDate->Width = 100;
   ts2->GridColumnStyles->Add( cOrderDate );
   
   /*Use a PropertyDescriptor to create a formatted
     column. First get the PropertyDescriptorCollection
     for the data source and data member. */
   System::ComponentModel::PropertyDescriptorCollection^ pcol = this->
       BindingContext[myDataSet, "Customers::custToOrders"]->
       GetItemProperties();
   
   /* Create a formatted column using a PropertyDescriptor.
     The formatting character S"c" specifies a currency format. */
   DataGridColumnStyle^ csOrderAmount =
      gcnew DataGridTextBoxColumn( pcol[ "OrderAmount" ],"c",true );
   csOrderAmount->MappingName = "OrderAmount";
   csOrderAmount->HeaderText = "Total";
   csOrderAmount->Width = 100;
   ts2->GridColumnStyles->Add( csOrderAmount );
   
   /* Add the DataGridTableStyle instances to
     the GridTableStylesCollection. */
   myDataGrid->TableStyles->Add( ts1 );
   myDataGrid->TableStyles->Add( ts2 );
}
private void AddCustomDataTableStyle(){
   DataGridTableStyle ts1 = new DataGridTableStyle();
   ts1.MappingName = "Customers";
   // Set other properties.
   ts1.AlternatingBackColor = Color.LightGray;

   /* Add a GridColumnStyle and set its MappingName 
   to the name of a DataColumn in the DataTable. 
   Set the HeaderText and Width properties. */
   
   DataGridColumnStyle boolCol = new DataGridBoolColumn();
   boolCol.MappingName = "Current";
   boolCol.HeaderText = "IsCurrent Customer";
   boolCol.Width = 150;
   ts1.GridColumnStyles.Add(boolCol);
   
   // Add a second column style.
   DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
   TextCol.MappingName = "custName";
   TextCol.HeaderText = "Customer Name";
   TextCol.Width = 250;
   ts1.GridColumnStyles.Add(TextCol);

   // Create the second table style with columns.
   DataGridTableStyle ts2 = new DataGridTableStyle();
   ts2.MappingName = "Orders";

   // Set other properties.
   ts2.AlternatingBackColor = Color.LightBlue;
   
   // Create new ColumnStyle objects.
   DataGridColumnStyle cOrderDate = 
   new DataGridTextBoxColumn();
   cOrderDate.MappingName = "OrderDate";
   cOrderDate.HeaderText = "Order Date";
   cOrderDate.Width = 100;
   ts2.GridColumnStyles.Add(cOrderDate);

   /*Use a PropertyDescriptor to create a formatted
   column. First get the PropertyDescriptorCollection
   for the data source and data member. */
   System.ComponentModel.PropertyDescriptorCollection pcol = 
      this.BindingContext[myDataSet, "Customers.custToOrders"]
      .GetItemProperties();
 
   /* Create a formatted column using a PropertyDescriptor.
   The formatting character "c" specifies a currency format. */     
   DataGridColumnStyle csOrderAmount = 
   new DataGridTextBoxColumn(pcol["OrderAmount"], "c", true);
   csOrderAmount.MappingName = "OrderAmount";
   csOrderAmount.HeaderText = "Total";
   csOrderAmount.Width = 100;
   ts2.GridColumnStyles.Add(csOrderAmount);

   /* Add the DataGridTableStyle instances to 
   the GridTableStylesCollection. */
   myDataGrid.TableStyles.Add(ts1);
   myDataGrid.TableStyles.Add(ts2);
}
Private Sub AddCustomDataTableStyle()
   Dim ts1 As New DataGridTableStyle()
   ts1.MappingName = "Customers"
   ' Set other properties.
   ts1.AlternatingBackColor = Color.LightGray
   ' Add a GridColumnStyle and set its MappingName 
   ' to the name of a DataColumn in the DataTable. 
   ' Set the HeaderText and Width properties. 
     
   Dim boolCol As New DataGridBoolColumn()
   boolCol.MappingName = "Current"
   boolCol.HeaderText = "IsCurrent Customer"
   boolCol.Width = 150
   ts1.GridColumnStyles.Add(boolCol)
     
   ' Add a second column style.
   Dim TextCol As New DataGridTextBoxColumn()
   TextCol.MappingName = "custName"
   TextCol.HeaderText = "Customer Name"
   TextCol.Width = 250
   ts1.GridColumnStyles.Add(TextCol)
     
   ' Create the second table style with columns.
   Dim ts2 As New DataGridTableStyle()
   ts2.MappingName = "Orders"
     
   ' Set other properties.
   ts2.AlternatingBackColor = Color.LightBlue
     
   ' Create new ColumnStyle objects.
   Dim cOrderDate As New DataGridTextBoxColumn()
   cOrderDate.MappingName = "OrderDate"
   cOrderDate.HeaderText = "Order Date"
   cOrderDate.Width = 100
   ts2.GridColumnStyles.Add(cOrderDate)

   ' Use a PropertyDescriptor to create a formatted
   ' column. First get the PropertyDescriptorCollection
   ' for the data source and data member. 
   Dim pcol As System.ComponentModel.PropertyDescriptorCollection = _
   Me.BindingContext(myDataSet, "Customers.custToOrders"). _
   GetItemProperties()

   ' Create a formatted column using a PropertyDescriptor.
   ' The formatting character "c" specifies a currency format. */     
     
   Dim csOrderAmount As _
   New DataGridTextBoxColumn(pcol("OrderAmount"), "c", True)
   csOrderAmount.MappingName = "OrderAmount"
   csOrderAmount.HeaderText = "Total"
   csOrderAmount.Width = 100
   ts2.GridColumnStyles.Add(csOrderAmount)
     
   ' Add the DataGridTableStyle instances to 
   ' the GridTableStylesCollection. 
   myDataGrid.TableStyles.Add(ts1)
   myDataGrid.TableStyles.Add(ts2)
End Sub

注釈

GridTableStylesCollectionには、 DataGridTableStyle コントロールが 内のDataGridそれぞれのDataTableカスタマイズされたグリッド スタイルを表示できるようにする オブジェクトがDataSet含まれています。

コントロールで DataGrid 、 プロパティは TableStyles を返します GridTableStylesCollection

既定では、 GridTableStylesCollection にはオブジェクトは含 DataGridTableStyle まれません。 代わりに、 では DataGrid 、色、幅、書式設定の既定の設定を使用して各テーブルが表示されます。 各テーブルのすべての列が表示されます。 DataGridTableStyleがコレクションに追加されると、 DataGrid は をMappingName使用して、グリッドのデータを提供するオブジェクトを決定します。 たとえば、データ ソースが 3 つのDataTableオブジェクトを含む であるDataSet場合、 MappingName はいずれかのオブジェクトの とTableName一致する必要があります。 MappingNameがいずれの値にもTableName一致しない場合、各テーブルのデータを表示するために既定のDataGridTableStyle設定が使用され、設定は無視されます。

注意事項

にオブジェクトを追加する前に、常に オブジェクトをGridColumnStylesCollection作成DataGridColumnStyleし、 GridTableStylesCollectionに追加DataGridTableStyleします。 有効なMappingName値を持つ空DataGridTableStyleの をコレクションに追加すると、DataGridColumnStyleオブジェクトが自動的に生成されます。 したがって、重複するMappingName値を持つ新しいDataGridColumnStyleオブジェクトを に追加しようとすると、例外がGridColumnStylesCollectionスローされます。 または、 メソッドを使用して をGridColumnStylesCollectionClearクリアします。

プロパティ

Count

コレクション内の要素の総数を取得します。

(継承元 BaseCollection)
IsReadOnly

コレクションが読み取り専用かどうかを示す値を取得します。

(継承元 BaseCollection)
IsSynchronized

ICollection へのアクセスの同期がとられているかどうかを示す値を取得します。

(継承元 BaseCollection)
Item[Int32]

インデックスで指定した DataGridTableStyle を取得します。

Item[String]

指定された名前を持つ DataGridTableStyle を取得します。

List

基になるリストを取得します。

SyncRoot

BaseCollection へのアクセスを同期するために使用できるオブジェクトを取得します。

(継承元 BaseCollection)

メソッド

Add(DataGridTableStyle)

DataGridTableStyle をコレクションに追加します。

AddRange(DataGridTableStyle[])

テーブル スタイルの配列をコレクションに追加します。

Clear()

コレクションを空にします。

Contains(DataGridTableStyle)

指定した GridTableStylesCollectionDataGridTableStyle に格納されているかどうかを示す値を取得します。

Contains(String)

名前で指定した GridTableStylesCollectionDataGridTableStyle に格納されているかどうかを示す値を取得します。

CopyTo(Array, Int32)

現在の 1 次元 Array のすべての要素を、指定した 1 次元 ArrayArray の指定したコピー先インデックスを開始位置としてコピーします。

(継承元 BaseCollection)
CreateObjRef(Type)

リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。

(継承元 MarshalByRefObject)
Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEnumerator()

コレクションのメンバーを反復処理できるオブジェクトを取得します。

(継承元 BaseCollection)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
古い.

対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

CollectionChanged イベントを発生させます。

Remove(DataGridTableStyle)

指定した DataGridTableStyle を削除します。

RemoveAt(Int32)

指定したインデックス位置にある DataGridTableStyle を削除します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

イベント

CollectionChanged

コレクションが変更されたときに発生します。

明示的なインターフェイスの実装

ICollection.CopyTo(Array, Int32)

コレクションを互換性のある 1 次元の Array にコピーします。コピー操作は、コピー先の配列の指定したインデックスから始まります。

ICollection.Count

コレクション内の項目の数を取得します。

ICollection.IsSynchronized

GridTableStylesCollection へのアクセスが同期されている (スレッド セーフである) かどうかを示す値を取得します。

ICollection.SyncRoot

コレクションへのアクセスを同期するために使用できるオブジェクトを取得します。

IEnumerable.GetEnumerator()

コレクションの列挙子を返します。

IList.Add(Object)

DataGridTableStyle をコレクションに追加します。

IList.Clear()

コレクションを空にします。

IList.Contains(Object)

ある要素がコレクション内に存在するかどうかを判断します。

IList.IndexOf(Object)

指定したオブジェクトがコレクション内で最初に出現する位置の、0 から始まるインデックスを返します。

IList.Insert(Int32, Object)

Insert(Int32, Object) メソッドを実装します。 常に NotSupportedException をスローします。

IList.IsFixedSize

コレクションが固定サイズかどうかを示す値を取得します。

IList.IsReadOnly

コレクションが読み取り専用かどうかを示す値を取得します。

IList.Item[Int32]

指定したインデックスにある要素を取得または設定します。

IList.Remove(Object)

指定した DataGridTableStyle を削除します。

IList.RemoveAt(Int32)

指定したインデックスの DataGridColumnStyle をコレクションから削除します。

拡張メソッド

Cast<TResult>(IEnumerable)

IEnumerable の要素を、指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定された型に基づいて IEnumerable の要素をフィルター処理します。

AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください