DataGridViewColumnCollection クラス

定義

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

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

次のコード例は、この型の使用方法を示しています。

private DataGridView dataGridView1 = new DataGridView();

private void AddColorColumn()
{
    DataGridViewComboBoxColumn comboBoxColumn =
        new DataGridViewComboBoxColumn();
    comboBoxColumn.Items.AddRange(
        Color.Red, Color.Yellow, Color.Green, Color.Blue);
    comboBoxColumn.ValueType = typeof(Color);
    dataGridView1.Columns.Add(comboBoxColumn);
    dataGridView1.EditingControlShowing +=
        new DataGridViewEditingControlShowingEventHandler(
        dataGridView1_EditingControlShowing);
}

private void dataGridView1_EditingControlShowing(object sender,
    DataGridViewEditingControlShowingEventArgs e)
{
    ComboBox combo = e.Control as ComboBox;
    if (combo != null)
    {
        // Remove an existing event-handler, if present, to avoid 
        // adding multiple handlers when the editing control is reused.
        combo.SelectedIndexChanged -=
            new EventHandler(ComboBox_SelectedIndexChanged);

        // Add the event handler. 
        combo.SelectedIndexChanged +=
            new EventHandler(ComboBox_SelectedIndexChanged);
    }
}

private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    ((ComboBox)sender).BackColor = (Color)((ComboBox)sender).SelectedItem;
}
Private WithEvents dataGridView1 As New DataGridView()

Private Sub AddColorColumn()

    Dim comboBoxColumn As New DataGridViewComboBoxColumn()
    comboBoxColumn.Items.AddRange( _
        Color.Red, Color.Yellow, Color.Green, Color.Blue)
    comboBoxColumn.ValueType = GetType(Color)
    dataGridView1.Columns.Add(comboBoxColumn)

End Sub

Private Sub dataGridView1_EditingControlShowing(ByVal sender As Object, _
    ByVal e As DataGridViewEditingControlShowingEventArgs) _
    Handles dataGridView1.EditingControlShowing

    Dim combo As ComboBox = CType(e.Control, ComboBox)
    If (combo IsNot Nothing) Then

        ' Remove an existing event-handler, if present, to avoid 
        ' adding multiple handlers when the editing control is reused.
        RemoveHandler combo.SelectedIndexChanged, _
            New EventHandler(AddressOf ComboBox_SelectedIndexChanged)

        ' Add the event handler. 
        AddHandler combo.SelectedIndexChanged, _
            New EventHandler(AddressOf ComboBox_SelectedIndexChanged)

    End If

End Sub

Private Sub ComboBox_SelectedIndexChanged( _
    ByVal sender As Object, ByVal e As EventArgs)

    Dim comboBox1 As ComboBox = CType(sender, ComboBox)
    comboBox1.BackColor = _
        CType(CType(sender, ComboBox).SelectedItem, Color)

End Sub

注釈

このクラスのインスタンスは、 コントロールの DataGridView プロパティをColumns使用して取得できます。 コレクションは、 プロパティを使用してコントロールへの参照を DataGridView 保持します。

コンストラクター

DataGridViewColumnCollection(DataGridView)

指定した DataGridViewColumnCollectionDataGridView クラスの新しいインスタンスを初期化します。

プロパティ

Count

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

(継承元 BaseCollection)
DataGridView

コレクションが列関連の処理を実行する DataGridView を取得します。

IsReadOnly

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

(継承元 BaseCollection)
IsSynchronized

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

(継承元 BaseCollection)
Item[Int32]

コレクション内の指定したインデックスにある列を取得または設定します。

Item[String]

コレクション内にある指定した名前の列を取得または設定します。

List

BaseCollection インスタンスに格納されている要素のリストを取得します。

SyncRoot

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

(継承元 BaseCollection)

メソッド

Add(DataGridViewColumn)

指定した列をコレクションに追加します。

Add(String, String)

指定した列名と列ヘッダー テキストを持つ DataGridViewTextBoxColumn をコレクションに追加します。

AddRange(DataGridViewColumn[])

一連の列をコレクションに追加します。

Clear()

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

Contains(DataGridViewColumn)

指定した列がコレクションに格納されているかどうかを確認します。

Contains(String)

コレクションに、指定した名前によって参照される列が格納されているかどうかを判断します。

CopyTo(Array, Int32)

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

(継承元 BaseCollection)
CopyTo(DataGridViewColumn[], Int32)

指定した配列にコレクションの項目をコピーします。

CreateObjRef(Type)

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

(継承元 MarshalByRefObject)
Equals(Object)

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

(継承元 Object)
GetColumnCount(DataGridViewElementStates)

指定したフィルター条件に一致する列の数を返します。

GetColumnsWidth(DataGridViewElementStates)

指定したフィルター条件に一致する列をすべて表示するために必要な幅をピクセル単位で返します。

GetEnumerator()

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

(継承元 BaseCollection)
GetFirstColumn(DataGridViewElementStates)

指定した包含フィルター条件に一致する、表示順における最初の列を返します。

GetFirstColumn(DataGridViewElementStates, DataGridViewElementStates)

指定した包含フィルター条件と除外フィルター条件に一致する、表示順における最初の列を返します。

GetHashCode()

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

(継承元 Object)
GetLastColumn(DataGridViewElementStates, DataGridViewElementStates)

指定したフィルター条件に一致する、表示順における最後の列を返します。

GetLifetimeService()
古い.

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

(継承元 MarshalByRefObject)
GetNextColumn(DataGridViewColumn, DataGridViewElementStates, DataGridViewElementStates)

表示順で指定された列の後にあり、指定したフィルター条件に一致する最初の列を取得します。

GetPreviousColumn(DataGridViewColumn, DataGridViewElementStates, DataGridViewElementStates)

表示順で指定された列の前にあり、指定したフィルター条件に一致する最後の列を取得します。

GetType()

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

(継承元 Object)
IndexOf(DataGridViewColumn)

コレクション内の指定した DataGridViewColumn のインデックスを取得します。

InitializeLifetimeService()
古い.

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

(継承元 MarshalByRefObject)
Insert(Int32, DataGridViewColumn)

コレクション内の指定したインデックスに列を挿入します。

MemberwiseClone()

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

(継承元 Object)
MemberwiseClone(Boolean)

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

(継承元 MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

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

Remove(DataGridViewColumn)

指定した列をコレクションから削除します。

Remove(String)

指定した名前の列をコレクションから削除します。

RemoveAt(Int32)

指定したインデックス位置にある列をコレクションから削除します。

ToString()

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

(継承元 Object)

イベント

CollectionChanged

コレクションに変更が生じた場合に発生します。

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

ICollection.CopyTo(Array, Int32)

コピー先配列の指定されたインデックスを開始位置として、コレクションの内容全体を互換性がある 1 次元 Array にコピーします。

ICollection.Count

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

ICollection.IsSynchronized

コレクションへのアクセスが同期されるかどうかを示す値を取得します。

ICollection.SyncRoot

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

IEnumerable.GetEnumerator()

コレクションを反復処理する列挙子を返します。

IList.Add(Object)

オブジェクトをコレクションの末尾に追加します。

IList.Clear()

コレクションからすべての要素を削除します。

IList.Contains(Object)

オブジェクトがコレクション内に存在するかどうかを判断します。

IList.IndexOf(Object)

コレクション内での指定した項目のインデックスを調べます。

IList.Insert(Int32, Object)

要素をコレクション内の指定されたインデックス位置に挿入します。

IList.IsFixedSize

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

IList.IsReadOnly

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

IList.Item[Int32]

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

IList.Remove(Object)

コレクション内で最初に見つかった指定のオブジェクトを削除します。

IList.RemoveAt(Int32)

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

拡張メソッド

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください