GridTableStylesCollectionとは? わかりやすく解説

GridTableStylesCollection イベント


パブリック イベントパブリック イベント

  名前 説明
パブリック イベント CollectionChanged コレクションが変更された場合に発生します。
参照参照

関連項目

GridTableStylesCollection クラス
System.Windows.Forms 名前空間
DataGrid クラス
DataGridTableStyle.GridColumnStyles プロパティ

GridTableStylesCollection クラス

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

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Class GridTableStylesCollection
    Inherits BaseCollection
    Implements IList, ICollection, IEnumerable
Dim instance As GridTableStylesCollection
public class GridTableStylesCollection : BaseCollection,
 IList, ICollection, IEnumerable
public ref class GridTableStylesCollection
 : public BaseCollection, IList, ICollection, IEnumerable
public class GridTableStylesCollection extends
 BaseCollection implements IList, ICollection, 
    IEnumerable
public class GridTableStylesCollection extends
 BaseCollection implements IList, ICollection, 
    IEnumerable
解説解説

GridTableStylesCollection は DataGridTableStyle オブジェクトを格納します。DataGrid コントロールは、このオブジェクトを使用して DataSet 内の各 DataTable にカスタマイズされたグリッド スタイルを表示できます。

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

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

注意に関するメモ注意

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

使用例使用例

2 つの DataGridTableStyle オブジェクトを作成し、各オブジェクトを DataGrid コントロールの TableStyles プロパティから返された GridTableStylesCollection に追加するコード例を次に示します。

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 'AddCustomDataTableStyle
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);
}
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.set_MappingName("Customers");

    // Set other properties.
    ts1.set_AlternatingBackColor(Color.get_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.set_MappingName("Current");
    boolCol.set_HeaderText("IsCurrent Customer");
    boolCol.set_Width(150);
    ts1.get_GridColumnStyles().Add(boolCol);

    // Add a second column style.
    DataGridColumnStyle TextCol = new DataGridTextBoxColumn();

    TextCol.set_MappingName("custName");
    TextCol.set_HeaderText("Customer Name");
    TextCol.set_Width(250);
    ts1.get_GridColumnStyles().Add(TextCol);

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

    // Set other properties.
    ts2.set_AlternatingBackColor(Color.get_LightBlue());

    // Create new ColumnStyle objects.
    DataGridColumnStyle cOrderDate = new DataGridTextBoxColumn();

    cOrderDate.set_MappingName("OrderDate");
    cOrderDate.set_HeaderText("Order Date");
    cOrderDate.set_Width(100);
    ts2.get_GridColumnStyles().Add(cOrderDate);

    /*  Use a PropertyDescriptor to create a formatted column. First get
 the 
        the PropertyDescriptorCollection for the data source and
 data member. 
    */
    PropertyDescriptorCollection pcol = this.get_BindingContext().
        get_Item(myDataSet, "Customers.custToOrders").GetItemProperties();

    /*  Create a formatted column using a PropertyDescriptor.
        The formatting character "c" specifies a currency format.
     */
    DataGridColumnStyle csOrderAmount = new DataGridTextBoxColumn(pcol.
        get_Item("OrderAmount"), "c", true);

    csOrderAmount.set_MappingName("OrderAmount");
    csOrderAmount.set_HeaderText("Total");
    csOrderAmount.set_Width(100);
    ts2.get_GridColumnStyles().Add(csOrderAmount);

    /*  Add the DataGridTableStyle instances to 
        the GridTableStylesCollection. 
     */
    myDataGrid.get_TableStyles().Add(ts1);
    myDataGrid.get_TableStyles().Add(ts2);
} //AddCustomDataTableStyle
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.Windows.Forms.BaseCollection
      System.Windows.Forms.GridTableStylesCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GridTableStylesCollection メンバ
System.Windows.Forms 名前空間
DataGrid クラス
DataGridTableStyle.GridColumnStyles プロパティ

GridTableStylesCollection プロパティ


パブリック プロパティパブリック プロパティ

( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ Count  コレクション内の要素の合計数を取得します。 ( BaseCollection から継承されます。)
パブリック プロパティ IsReadOnly  コレクションが読み取り専用かどうかを示す値を取得します。 ( BaseCollection から継承されます。)
パブリック プロパティ IsSynchronized  ICollection へのアクセスの同期がとられているかどうかを示す値を取得します。 ( BaseCollection から継承されます。)
パブリック プロパティ Item オーバーロードされます。 指定した DataGridTableStyle を取得します。
パブリック プロパティ SyncRoot  BaseCollection へのアクセスを同期するために使用できるオブジェクトを取得します。 ( BaseCollection から継承されます。)
プロテクト プロパティプロテクト プロパティ
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.IList.Item 指定したインデックスにある要素を取得または設定します。
参照参照

関連項目

GridTableStylesCollection クラス
System.Windows.Forms 名前空間
DataGrid クラス
DataGridTableStyle.GridColumnStyles プロパティ

GridTableStylesCollection メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Add DataGridTableStyle をコレクションに追加します。
パブリック メソッド AddRange テーブル スタイルの配列をコレクションに追加します。
パブリック メソッド Clear コレクションを空にします。
パブリック メソッド Contains オーバーロードされます。 指定した DataGridTableStyle が GridTableStylesCollection に格納されているかどうかを示す値を取得します。
パブリック メソッド CopyTo  指定したコピー先の Array インデックスを開始位置として、現在の 1 次元 Array のすべての要素を指定した 1 次元 Array にコピーします。 ( BaseCollection から継承されます。)
パブリック メソッド CreateObjRef  リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 ( MarshalByRefObject から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator  コレクションのメンバを反復処理できるオブジェクトを取得します。 ( BaseCollection から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetLifetimeService  対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 ( MarshalByRefObject から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド InitializeLifetimeService  対象のインスタンスの有効期間ポリシーを制御する、有効期間サービス オブジェクトを取得します。 ( MarshalByRefObject から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド Remove 指定した DataGridTableStyle を削除します。
パブリック メソッド RemoveAt 指定したインデックス位置にある DataGridTableStyle を削除します。
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo コレクションを互換性のある 1 次元の Array にコピーします。コピー操作は、コピー先の配列の指定したインデックスから始まります。
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクションの列挙子を返します。
インターフェイスの明示的な実装 System.Collections.IList.Add DataGridTableStyle をコレクションに追加します。
インターフェイスの明示的な実装 System.Collections.IList.Clear コレクションを空にします。
インターフェイスの明示的な実装 System.Collections.IList.Contains ある要素がコレクション内に存在するかどうかを判断します。
インターフェイスの明示的な実装 System.Collections.IList.IndexOf コレクション内にある指定したオブジェクトのうち、最初に出現する値の、0 から始まるインデックス番号を返します。
インターフェイスの明示的な実装 System.Collections.IList.Insert Insert メソッドを実装します。常に NotSupportedException をスローします。
インターフェイスの明示的な実装 System.Collections.IList.Remove 指定した DataGridTableStyle を削除します。
インターフェイスの明示的な実装 System.Collections.IList.RemoveAt 指定したインデックスの DataGridColumnStyle をコレクションから削除します。
参照参照

関連項目

GridTableStylesCollection クラス
System.Windows.Forms 名前空間
DataGrid クラス
DataGridTableStyle.GridColumnStyles プロパティ

GridTableStylesCollection メンバ

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

GridTableStylesCollection データ型で公開されるメンバを以下の表に示します。


パブリック プロパティパブリック プロパティ
( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ Count  コレクション内の要素の合計数を取得します。(BaseCollection から継承されます。)
パブリック プロパティ IsReadOnly  コレクションが読み取り専用かどうかを示す値を取得します。(BaseCollection から継承されます。)
パブリック プロパティ IsSynchronized  ICollection へのアクセスの同期がとられているかどうかを示す値を取得します。(BaseCollection から継承されます。)
パブリック プロパティ Item オーバーロードされます。 指定した DataGridTableStyle を取得します。
パブリック プロパティ SyncRoot  BaseCollection へのアクセスを同期するために使用できるオブジェクトを取得します。(BaseCollection から継承されます。)
プロテクト プロパティプロテクト プロパティ
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Add DataGridTableStyle をコレクションに追加します。
パブリック メソッド AddRange テーブル スタイルの配列をコレクションに追加します。
パブリック メソッド Clear コレクションを空にします。
パブリック メソッド Contains オーバーロードされます。 指定した DataGridTableStyle が GridTableStylesCollection に格納されているかどうかを示す値を取得します。
パブリック メソッド CopyTo  指定したコピー先の Array インデックスを開始位置として、現在の 1 次元 Array のすべての要素を指定した 1 次元 Array にコピーします。 (BaseCollection から継承されます。)
パブリック メソッド CreateObjRef  リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 (MarshalByRefObject から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator  コレクションのメンバを反復処理できるオブジェクトを取得します。 (BaseCollection から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetLifetimeService  対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 (MarshalByRefObject から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド InitializeLifetimeService  対象のインスタンスの有効期間ポリシーを制御する、有効期間サービス オブジェクトを取得します。 (MarshalByRefObject から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド Remove 指定した DataGridTableStyle を削除します。
パブリック メソッド RemoveAt 指定したインデックス位置にある DataGridTableStyle を削除します。
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
パブリック イベントパブリック イベント
  名前 説明
パブリック イベント CollectionChanged コレクションが変更された場合に発生します。
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo コレクションを互換性のある 1 次元の Array にコピーします。コピー操作は、コピー先の配列の指定したインデックスから始まります。
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクションの列挙子を返します。
インターフェイスの明示的な実装 System.Collections.IList.Add DataGridTableStyle をコレクションに追加します。
インターフェイスの明示的な実装 System.Collections.IList.Clear コレクションを空にします。
インターフェイスの明示的な実装 System.Collections.IList.Contains ある要素がコレクション内に存在するかどうかを判断します。
インターフェイスの明示的な実装 System.Collections.IList.IndexOf コレクション内にある指定したオブジェクトのうち、最初に出現する値の、0 から始まるインデックス番号を返します。
インターフェイスの明示的な実装 System.Collections.IList.Insert Insert メソッドを実装します。常に NotSupportedException をスローします。
インターフェイスの明示的な実装 System.Collections.IList.Remove 指定した DataGridTableStyle を削除します。
インターフェイスの明示的な実装 System.Collections.IList.RemoveAt 指定したインデックスの DataGridColumnStyle をコレクションから削除します。
インターフェイスの明示的な実装 System.Collections.IList.Item 指定したインデックスにある要素を取得または設定します。
参照参照

関連項目

GridTableStylesCollection クラス
System.Windows.Forms 名前空間
DataGrid クラス
DataGridTableStyle.GridColumnStyles プロパティ



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「GridTableStylesCollection」の関連用語

GridTableStylesCollectionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



GridTableStylesCollectionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS