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

DataGridColumnCollection クラス

DataGrid コントロールの列を表す DataGridColumn 派生オブジェクトコレクション。このクラス継承できません。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public NotInheritable Class
 DataGridColumnCollection
    Implements ICollection, IEnumerable, IStateManager
Dim instance As DataGridColumnCollection
public sealed class DataGridColumnCollection
 : ICollection, IEnumerable, IStateManager
public ref class DataGridColumnCollection sealed
 : ICollection, IEnumerable, IStateManager
public final class DataGridColumnCollection
 implements ICollection, IEnumerable, 
    IStateManager
public final class DataGridColumnCollection
 implements ICollection, IEnumerable, 
    IStateManager
解説解説

DataGridColumnCollection コレクション使用してDataGridColumn 派生オブジェクトコレクションプログラムによって管理します。これらのオブジェクトDataGrid コントロール内の列を表しますDataGridColumnCollection コレクションに列を追加削除、または挿入できます

メモメモ

AutoGenerateColumns プロパティtrue,設定すると、DataGrid コントロール作成した列は Columns コレクション追加されません。

DataGrid コントロールは、その Columns コレクション内容ビューステートには格納しません。列を動的に追加または削除するには、ページ更新されるたびにプログラムによって列を追加または削除する必要がありますDataGrid コントロールの状態再読み込みしてコントロール自体再度ビルドする前に、列を追加または削除する Page_Init 関数提供しますそれ以外場合は、Columns コレクション対す変更内容が、DataGrid コントロール表示されるときに反映されません。

メモメモ

DataGrid コントロールColumns コレクションに、プログラムによって列を追加または削除できますが、列を静的一覧表示してから、Visible プロパティ使用して各列を表示するか、非表示にする方が簡単です。

DataGrid コントロールに列が表示される順序は、コレクションの中の列の順序によって決まります

DataGridColumn クラスから派生したさまざまなクラスの一覧を次の表に示します

列のクラス

説明

BoundColumn

データ ソースフィールド連結されている列。各項目はフィールドテキストとして表示されます。DataGrid コントロール既定の列型です。

ButtonColumn

内の各項目に関するコマンド ボタン表示する列。この列を使用して、[Add] ボタンや [Remove] ボタンなどのカスタム ボタン コントロールの列を作成できます

EditCommandColumn

内の各項目に対す編集コマンド格納されている列。

HyperLinkColumn

内の各項目をハイパーリンクとして表示する列。列の内容は、データ ソースフィールド、または静的テキスト連結できます

TemplateColumn

指定されテンプレートに従って、列内の各項目を表示する列。この列を使用して表示イメージなどの列の内容制御できます

メモメモ

DataGridColumn クラスは、一覧表示されている列のクラス基本クラスです。このクラスは、DataGridColumnCollection コレクションでは直接には使用されません。

使用例使用例

DataGridColumnCollection コレクション使用してDataGrid コントロールに列を動的に追加する方法次のコード示しますDataGrid コントロールColumns プロパティは、DataGridColumnCollection クラスインスタンスです。

<%@ Page Language="VB" AutoEventWireup="True"
 %>
<%@ Import Namespace="System.Data"
 %>
 
<html>
   <script runat="server">

      Function CreateDataSource() As ICollection
 
      
         ' Create sample data for the DataGrid control.
         Dim dt As DataTable = New
 DataTable()
         Dim dr As DataRow
 
         ' Define the columns of the table.
         dt.Columns.Add(New DataColumn("IntegerValue",
 GetType(Int32)))
         dt.Columns.Add(New DataColumn("StringValue",
 GetType(string)))
         dt.Columns.Add(New DataColumn("CurrencyValue",
 GetType(double)))
 
         ' Populate the table with sample values.
         Dim i As Integer

         For i = 0 to 8 
        
            dr = dt.NewRow()
 
            dr(0) = i
            dr(1) = "Item " & i.ToString()
            dr(2) = 1.23 * (i + 1)
 
            dt.Rows.Add(dr)

         Next i
 
         Dim dv As DataView = New
 DataView(dt)
         Return dv

      End Function
 
      Sub Page_Load(sender As Object,
 e As EventArgs) 

         ' Create a DataGrid control.
         Dim ItemsGrid As DataGrid = New
 DataGrid()

         ' Set the properties of the DataGrid.
         ItemsGrid.ID = "ItemsGrid"
         ItemsGrid.BorderColor = System.Drawing.Color.Black
         ItemsGrid.CellPadding = 3
         ItemsGrid.AutoGenerateColumns = False

         ' Set the styles for the DataGrid.
         ItemsGrid.HeaderStyle.BackColor = System.Drawing.Color.FromArgb(&H0000aaaa)

         ' Create the columns for the DataGrid control. The DataGrid
         ' columns are dynamically generated. Therefore, the columns
   
         ' must be re-created each time the page is refreshed.
         
         ' Create and add the columns to the collection.
         ItemsGrid.Columns.Add(CreateBoundColumn("IntegerValue",
 "Item"))
         ItemsGrid.Columns.Add( _
             CreateBoundColumn("StringValue", "Description"))
         ItemsGrid.Columns.Add( _
             CreateBoundColumn("CurrencyValue", "Price",
 "{0:c}", _
             HorizontalAlign.Right))
         ItemsGrid.Columns.Add( _
             CreateLinkColumn("http:'www.microsoft.com", "_self",
 _
             "Microsoft", "Related
 link"))
        
         ' Specify the data source and bind it to the control.     
         ItemsGrid.DataSource = CreateDataSource()
         ItemsGrid.DataBind()

         ' Add the DataGrid control to the Controls collection of 
         ' the PlaceHolder control.
         Place.Controls.Add(ItemsGrid)

      End Sub

      Function CreateBoundColumn(DataFieldValue As
 String, HeaderTextValue As String)
 As BoundColumn

         ' This version of CreateBoundColumn method sets only the 
         ' DataField and HeaderText properties.

         ' Create a BoundColumn.
         Dim column As BoundColumn = New
 BoundColumn()

         ' Set the properties of the BoundColumn.
         column.DataField = DataFieldValue
         column.HeaderText = HeaderTextValue

         Return column

      End Function

      Function CreateBoundColumn(DataFieldValue As
 String, _
          HeaderTextValue As String, FormatValue
 As String, _
          AlignValue As HorizontalAlign) As
 BoundColumn

         ' This version of CreateBoundColumn method sets the DataField
,
         ' HeaderText, and DataFormatString properties. It also sets
 the 
         ' HorizontalAlign property of the ItemStyle property of the
 column. 

         ' Create a BoundColumn using the overloaded CreateBoundColumn
 method.
         Dim column As BoundColumn = CreateBoundColumn(DataFieldValue,
 HeaderTextValue)

         ' Set the properties of the BoundColumn.
         column.DataFormatString = FormatValue
         column.ItemStyle.HorizontalAlign = AlignValue

         Return column

      End Function

      Function CreateLinkColumn(NavUrlValue As
 String, TargetValue As String,
 _
         TextValue As String, HeaderTextValue
 As String) As HyperLinkColumn
 

         ' Create a BoundColumn.
         Dim column As HyperLinkColumn = New
 HyperLinkColumn()

         ' Set the properties of the ButtonColumn.
         column.NavigateUrl = NavUrlValue
         column.Target = TargetValue
         column.Text = TextValue
         column.HeaderText = HeaderTextValue

         Return column

      End Function

   </script>
 
<body>
 
   <form runat=server>
 
      <h3>DataGrid Constructor Example</h3>
 
      <b>Product List</b>

      <asp:PlaceHolder id="Place"
           runat="server"/>
 
   </form>
 
</body>
</html>

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<html>
   <script runat="server">

      ICollection CreateDataSource() 
      {
      
         // Create sample data for the DataGrid control.
         DataTable dt = new DataTable();
         DataRow dr;
 
         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("IntegerValue",
 typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue",
 typeof(string)));
         dt.Columns.Add(new DataColumn("CurrencyValue",
 typeof(double)));
 
         // Populate the table with sample values.
         for (int i = 0; i < 9; i++) 
         {
            dr = dt.NewRow();
 
            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = 1.23 * (i + 1);
 
            dt.Rows.Add(dr);
         }
 
         DataView dv = new DataView(dt);
         return dv;

      }
 
      void Page_Load(Object sender, EventArgs e) 
      {

         // Create a DataGrid control.
         DataGrid ItemsGrid = new DataGrid();

         // Set the properties of the DataGrid.
         ItemsGrid.ID = "ItemsGrid";
         ItemsGrid.BorderColor = System.Drawing.Color.Black;
         ItemsGrid.CellPadding = 3;
         ItemsGrid.AutoGenerateColumns = false;

         // Set the styles for the DataGrid.
         ItemsGrid.HeaderStyle.BackColor = 
             System.Drawing.Color.FromArgb(0x0000aaaa);

         // Create the columns for the DataGrid control. The DataGrid
         // columns are dynamically generated. Therefore, the columns
   
         // must be re-created each time the page is refreshed.
         
         // Create and add the columns to the collection.
         ItemsGrid.Columns.Add(CreateBoundColumn("IntegerValue", "Item"));
         ItemsGrid.Columns.Add(
             CreateBoundColumn("StringValue", "Description"));
         ItemsGrid.Columns.Add(
             CreateBoundColumn("CurrencyValue", "Price", "{0:c}",
 
             HorizontalAlign.Right));
         ItemsGrid.Columns.Add(
             CreateLinkColumn("http://www.microsoft.com",
 "_self", 
             "Microsoft", "Related link"));
        
         // Specify the data source and bind it to the control.
         ItemsGrid.DataSource = CreateDataSource();
         ItemsGrid.DataBind();

         // Add the DataGrid control to the Controls collection of 
         // the PlaceHolder control.
         Place.Controls.Add(ItemsGrid);

      }

      BoundColumn CreateBoundColumn(String DataFieldValue, 
          String HeaderTextValue)
      {

         // This version of the CreateBoundColumn method sets only the
         // DataField and HeaderText properties.

         // Create a BoundColumn.
         BoundColumn column = new BoundColumn();

         // Set the properties of the BoundColumn.
         column.DataField = DataFieldValue;
         column.HeaderText = HeaderTextValue;

         return column;

      }

      BoundColumn CreateBoundColumn(String DataFieldValue, 
          String HeaderTextValue, String FormatValue, 
          HorizontalAlign AlignValue)
      {

         // This version of CreateBoundColumn method sets the DataField
,
         // HeaderText, and DataFormatString properties. It also sets
 the 
         // HorizontalAlign property of the ItemStyle property of the
 column. 

         // Create a BoundColumn using the overloaded CreateBoundColumn
 method.
         BoundColumn column = CreateBoundColumn(DataFieldValue, HeaderTextValue);

         // Set the properties of the BoundColumn.
         column.DataFormatString = FormatValue;
         column.ItemStyle.HorizontalAlign = AlignValue;

         return column;

      }

      HyperLinkColumn CreateLinkColumn(String NavUrlValue, 
          String TargetValue, String TextValue, String HeaderTextValue)
      {

         // Create a BoundColumn.
         HyperLinkColumn column = new HyperLinkColumn();

         // Set the properties of the ButtonColumn.
         column.NavigateUrl = NavUrlValue;
         column.Target = TargetValue;
         column.Text = TextValue;
         column.HeaderText = HeaderTextValue;

         return column;

      }

   </script>
 
<body>
 
   <form runat=server>
 
      <h3>DataGrid Constructor Example</h3>
 
      <b>Product List</b>

      <asp:PlaceHolder id="Place"
           runat="server"/>
 
   </form>
 
</body>
</html>

継承階層継承階層
System.Object
  System.Web.UI.WebControls.DataGridColumnCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridColumnCollection メンバ
System.Web.UI.WebControls 名前空間
DataGrid クラス
DataGrid.Columns プロパティ
DataGridColumn クラス
BoundColumn クラス
ButtonColumn クラス
EditCommandColumn
HyperLinkColumn
TemplateColumn

DataGridColumnCollection コンストラクタ

DataGridColumnCollection クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    owner As DataGrid, _
    columns As ArrayList _
)
Dim owner As DataGrid
Dim columns As ArrayList

Dim instance As New DataGridColumnCollection(owner,
 columns)
public DataGridColumnCollection (
    DataGrid owner,
    ArrayList columns
)
public:
DataGridColumnCollection (
    DataGrid^ owner, 
    ArrayList^ columns
)
public DataGridColumnCollection (
    DataGrid owner, 
    ArrayList columns
)
public function DataGridColumnCollection (
    owner : DataGrid, 
    columns : ArrayList
)

パラメータ

owner

このコレクション対応する DataGrid コントロール

columns

列のコレクション格納する System.Collections.ArrayList。

解説解説
使用例使用例

DataGridColumnCollection クラス新しインスタンス作成および初期化する方法次のコード例示します

Sub Page_Init(sender As Object,
 e As EventArgs)
    Dim myList As New ArrayList()
    Dim myColumnCollection As New
 DataGridColumnCollection(ItemsGrid, myList)
End Sub 'Page_Init
void Page_Init(Object sender, EventArgs e) 
{
   ArrayList myList = new ArrayList();
   DataGridColumnCollection myColumnCollection = new DataGridColumnCollection(ItemsGrid,
 myList); 
}
   
void Page_Init(Object sender, EventArgs e)
{
    ArrayList myList = new ArrayList();
    DataGridColumnCollection myColumnCollection = 
        new DataGridColumnCollection(itemsGrid, myList);
} //Page_Init
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridColumnCollection クラス
DataGridColumnCollection メンバ
System.Web.UI.WebControls 名前空間
DataGrid クラス
System.Collections.ArrayList

DataGridColumnCollection プロパティ


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

  名前 説明
パブリック プロパティ Count DataGridColumnCollection コレクション内の列の数を取得します
パブリック プロパティ IsReadOnly DataGridColumnCollection コレクション内の列を変更できるかどうかを示す値を取得します
パブリック プロパティ IsSynchronized DataGridColumnCollection コレクションへのアクセス同期されている (スレッド セーフである) かどうかを示す値を取得します
パブリック プロパティ Item DataGridColumnCollection コレクション指定したインデックス位置にある DataGridColumn 派生オブジェクト取得します
パブリック プロパティ SyncRoot DataGridColumnCollection コレクションへのアクセス同期するために使用できるオブジェクト取得します
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Web.UI.IStateManager.IsTrackingViewState コレクションビューステート変更追跡しているかどうかを示す値を取得します
参照参照

関連項目

DataGridColumnCollection クラス
System.Web.UI.WebControls 名前空間
DataGrid クラス
DataGrid.Columns プロパティ
DataGridColumn クラス
BoundColumn クラス
ButtonColumn クラス
EditCommandColumn
HyperLinkColumn
TemplateColumn

DataGridColumnCollection メソッド


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

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Add 指定した DataGridColumn の派生オブジェクトを DataGridColumnCollection コレクション末尾追加します
パブリック メソッド AddAt DataGridColumnCollection コレクション内の指定したインデックス位置に、DataGridColumn 派生オブジェクト挿入します
パブリック メソッド Clear DataGridColumnCollection コレクションからすべての DataGridColumn派生オブジェクト削除します
パブリック メソッド CopyTo 指定した System.Array に DataGridColumnCollection コレクションの項目をコピーしますコピー操作は、System.Array 内の指定したインデックス位置から始まります
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator DataGridColumnCollection コレクションすべての DataGridColumn 派生オブジェクトを含む System.Collections.IEnumerator インターフェイス返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド IndexOf DataGridColumnCollection コレクション指定されDataGridColumn 派生オブジェクトインデックス返します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド Remove 指定した DataGridColumn派生オブジェクトDataGridColumnCollection コレクションから削除します
パブリック メソッド RemoveAt DataGridColumnCollection コレクション指定したインデックス位置にある DataGridColumn 派生オブジェクト削除します
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Web.UI.IStateManager.LoadViewState 以前保存した状態を読み込みます。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.SaveViewState 状態の変化を示すオブジェクト返します
インターフェイスの明示的な実装 System.Web.UI.IStateManager.TrackViewState 状態変化追跡開始します
参照参照

関連項目

DataGridColumnCollection クラス
System.Web.UI.WebControls 名前空間
DataGrid クラス
DataGrid.Columns プロパティ
DataGridColumn クラス
BoundColumn クラス
ButtonColumn クラス
EditCommandColumn
HyperLinkColumn
TemplateColumn

DataGridColumnCollection メンバ

DataGrid コントロールの列を表す DataGridColumn 派生オブジェクトコレクション。このクラス継承できません。

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DataGridColumnCollection DataGridColumnCollection クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Count DataGridColumnCollection コレクション内の列の数を取得します
パブリック プロパティ IsReadOnly DataGridColumnCollection コレクション内の列を変更できるかどうかを示す値を取得します
パブリック プロパティ IsSynchronized DataGridColumnCollection コレクションへのアクセス同期されている (スレッド セーフである) かどうかを示す値を取得します
パブリック プロパティ Item DataGridColumnCollection コレクション指定したインデックス位置にある DataGridColumn 派生オブジェクト取得します
パブリック プロパティ SyncRoot DataGridColumnCollection コレクションへのアクセス同期するために使用できるオブジェクト取得します
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Add 指定した DataGridColumn派生オブジェクトDataGridColumnCollection コレクション末尾追加します
パブリック メソッド AddAt DataGridColumnCollection コレクション内の指定したインデックス位置に、DataGridColumn 派生オブジェクト挿入します
パブリック メソッド Clear DataGridColumnCollection コレクションからすべての DataGridColumn派生オブジェクト削除します
パブリック メソッド CopyTo 指定した System.Array に DataGridColumnCollection コレクションの項目をコピーしますコピー操作は、System.Array 内の指定したインデックス位置から始まります
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator DataGridColumnCollection コレクションすべての DataGridColumn 派生オブジェクトを含む System.Collections.IEnumerator インターフェイス返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド IndexOf DataGridColumnCollection コレクション指定されDataGridColumn 派生オブジェクトインデックス返します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド Remove 指定した DataGridColumn派生オブジェクトDataGridColumnCollection コレクションから削除します
パブリック メソッド RemoveAt DataGridColumnCollection コレクション指定したインデックス位置にある DataGridColumn 派生オブジェクト削除します
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Web.UI.IStateManager.LoadViewState 以前保存した状態を読み込みます。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.SaveViewState 状態の変化を示すオブジェクト返します
インターフェイスの明示的な実装 System.Web.UI.IStateManager.TrackViewState 状態変化追跡開始します
インターフェイスの明示的な実装 System.Web.UI.IStateManager.IsTrackingViewState コレクションビューステート変更追跡しているかどうかを示す値を取得します
参照参照

関連項目

DataGridColumnCollection クラス
System.Web.UI.WebControls 名前空間
DataGrid クラス
DataGrid.Columns プロパティ
DataGridColumn クラス
BoundColumn クラス
ButtonColumn クラス
EditCommandColumn
HyperLinkColumn
TemplateColumn


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataGridColumnCollectionを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataGridColumnCollectionを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataGridColumnCollection を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataGridColumnCollection」の関連用語

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

   

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



DataGridColumnCollectionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS