DataGridViewColumnCollection クラス
定義
DataGridViewColumn コントロール内の DataGridView オブジェクトのコレクションを表します。Represents a collection of DataGridViewColumn objects in a DataGridView control.
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
- 継承
- 属性
- 実装
例
この型の使用方法を次のコード例に示します。The following code example illustrates the use of this type.
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
注釈
このクラスのインスタンスは、コントロールのプロパティを使用して取得でき Columns DataGridView ます。You can retrieve an instance of this class through the Columns property of the DataGridView control. コレクションは、プロパティを使用して、コントロールへの参照を保持し DataGridView ます。The collection maintains a reference to the control through the DataGridView property.
コンストラクター
DataGridViewColumnCollection(DataGridView) |
指定した DataGridViewColumnCollection の DataGridView クラスの新しいインスタンスを初期化します。Initializes a new instance of the DataGridViewColumnCollection class for the given DataGridView. |
プロパティ
Count |
コレクション内の要素の総数を取得します。Gets the total number of elements in the collection. (継承元 BaseCollection) |
DataGridView |
コレクションが列関連の処理を実行する DataGridView を取得します。Gets the DataGridView upon which the collection performs column-related operations. |
IsReadOnly |
コレクションが読み取り専用かどうかを示す値を取得します。Gets a value indicating whether the collection is read-only. (継承元 BaseCollection) |
IsSynchronized |
ICollection へのアクセスの同期がとられているかどうかを示す値を取得します。Gets a value indicating whether access to the ICollection is synchronized. (継承元 BaseCollection) |
Item[Int32] |
コレクション内の指定したインデックスにある列を取得または設定します。Gets or sets the column at the given index in the collection. |
Item[String] |
コレクション内にある指定した名前の列を取得または設定します。Gets or sets the column of the given name in the collection. |
List |
BaseCollection インスタンスに格納されている要素のリストを取得します。Gets the list of elements contained in the BaseCollection instance. |
SyncRoot |
BaseCollection へのアクセスを同期するために使用できるオブジェクトを取得します。Gets an object that can be used to synchronize access to the BaseCollection. (継承元 BaseCollection) |
メソッド
Add(DataGridViewColumn) |
指定した列をコレクションに追加します。Adds the given column to the collection. |
Add(String, String) |
指定した列名と列ヘッダー テキストを持つ DataGridViewTextBoxColumn をコレクションに追加します。Adds a DataGridViewTextBoxColumn with the given column name and column header text to the collection. |
AddRange(DataGridViewColumn[]) |
一連の列をコレクションに追加します。Adds a range of columns to the collection. |
Clear() |
コレクションを空にします。Clears the collection. |
Contains(DataGridViewColumn) |
指定した列がコレクションに格納されているかどうかを確認します。Determines whether the collection contains the given column. |
Contains(String) |
コレクションに、指定した名前によって参照される列が格納されているかどうかを判断します。Determines whether the collection contains the column referred to by the given name. |
CopyTo(Array, Int32) |
現在の 1 次元 Array のすべての要素を、指定した 1 次元 Array に Array の指定したコピー先インデックスを開始位置としてコピーします。Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index. (継承元 BaseCollection) |
CopyTo(DataGridViewColumn[], Int32) |
指定した配列にコレクションの項目をコピーします。Copies the items from the collection to the given array. |
CreateObjRef(Type) |
リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (継承元 MarshalByRefObject) |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object. (継承元 Object) |
GetColumnCount(DataGridViewElementStates) |
指定したフィルター条件に一致する列の数を返します。Returns the number of columns that meet the given filter requirements. |
GetColumnsWidth(DataGridViewElementStates) |
指定したフィルター条件に一致する列をすべて表示するために必要な幅をピクセル単位で返します。Returns the width, in pixels, required to display all of the columns that meet the given filter requirements. |
GetEnumerator() |
コレクションのメンバーを反復処理できるオブジェクトを取得します。Gets the object that enables iterating through the members of the collection. (継承元 BaseCollection) |
GetFirstColumn(DataGridViewElementStates) |
指定した包含フィルター条件に一致する、表示順における最初の列を返します。Returns the first column in display order that meets the given inclusion-filter requirements. |
GetFirstColumn(DataGridViewElementStates, DataGridViewElementStates) |
指定した包含フィルター条件と除外フィルター条件に一致する、表示順における最初の列を返します。Returns the first column in display order that meets the given inclusion-filter and exclusion-filter requirements. |
GetHashCode() |
既定のハッシュ関数として機能します。Serves as the default hash function. (継承元 Object) |
GetLastColumn(DataGridViewElementStates, DataGridViewElementStates) |
指定したフィルター条件に一致する、表示順における最後の列を返します。Returns the last column in display order that meets the given filter requirements. |
GetLifetimeService() |
対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。Retrieves the current lifetime service object that controls the lifetime policy for this instance. (継承元 MarshalByRefObject) |
GetNextColumn(DataGridViewColumn, DataGridViewElementStates, DataGridViewElementStates) |
表示順で指定された列の後にあり、指定したフィルター条件に一致する最初の列を取得します。Gets the first column after the given column in display order that meets the given filter requirements. |
GetPreviousColumn(DataGridViewColumn, DataGridViewElementStates, DataGridViewElementStates) |
表示順で指定された列の前にあり、指定したフィルター条件に一致する最後の列を取得します。Gets the last column prior to the given column in display order that meets the given filter requirements. |
GetType() |
現在のインスタンスの Type を取得します。Gets the Type of the current instance. (継承元 Object) |
IndexOf(DataGridViewColumn) |
コレクション内の指定した DataGridViewColumn のインデックスを取得します。Gets the index of the given DataGridViewColumn in the collection. |
InitializeLifetimeService() |
このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。Obtains a lifetime service object to control the lifetime policy for this instance. (継承元 MarshalByRefObject) |
Insert(Int32, DataGridViewColumn) |
コレクション内の指定したインデックスに列を挿入します。Inserts a column at the given index in the collection. |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object. (継承元 Object) |
MemberwiseClone(Boolean) |
現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。Creates a shallow copy of the current MarshalByRefObject object. (継承元 MarshalByRefObject) |
OnCollectionChanged(CollectionChangeEventArgs) |
CollectionChanged イベントを発生させます。Raises the CollectionChanged event. |
Remove(DataGridViewColumn) |
指定した列をコレクションから削除します。Removes the specified column from the collection. |
Remove(String) |
指定した名前の列をコレクションから削除します。Removes the column with the specified name from the collection. |
RemoveAt(Int32) |
指定したインデックス位置にある列をコレクションから削除します。Removes the column at the given index in the collection. |
ToString() |
現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object. (継承元 Object) |
イベント
CollectionChanged |
コレクションに変更が生じた場合に発生します。Occurs when the collection changes. |
明示的なインターフェイスの実装
ICollection.CopyTo(Array, Int32) |
コピー先配列の指定されたインデックスを開始位置として、コレクションの内容全体を互換性がある 1 次元 Array にコピーします。Copies the entire contents of the collection to a compatible one-dimensional Array, starting at the specified index of the target array. |
ICollection.Count |
コレクション内の要素の数を取得します。Gets the number of elements in the collection. |
ICollection.IsSynchronized |
コレクションへのアクセスが同期されるかどうかを示す値を取得します。Gets a value indicating whether access to the collection is synchronized. |
ICollection.SyncRoot |
コレクションへのアクセスを同期するために使用できるオブジェクトを取得します。Gets an object that can be used to synchronize access to the collection. |
IEnumerable.GetEnumerator() |
コレクションを反復処理する列挙子を返します。Returns an enumerator that iterates through the collection. |
IList.Add(Object) |
オブジェクトをコレクションの末尾に追加します。Adds an object to the end of the collection. |
IList.Clear() |
コレクションからすべての要素を削除します。Removes all elements from the collection. |
IList.Contains(Object) |
オブジェクトがコレクション内に存在するかどうかを判断します。Determines whether an object is in the collection. |
IList.IndexOf(Object) |
コレクション内の特定のアイテムのインデックスを示します。Determines the index of a specific item in the collection. |
IList.Insert(Int32, Object) |
要素をコレクション内の指定されたインデックス位置に挿入します。Inserts an element into the collection at the specified index. |
IList.IsFixedSize |
コレクションが固定サイズかどうかを示す値を取得します。Gets a value indicating whether the collection has a fixed size. |
IList.IsReadOnly |
コレクションが読み取り専用かどうかを示す値を取得します。Gets a value indicating whether the collection is read-only. |
IList.Item[Int32] |
指定したインデックスにある要素を取得または設定します。Gets or sets the element at the specified index. |
IList.Remove(Object) |
コレクション内で最初に見つかった指定のオブジェクトを削除します。Removes the first occurrence of the specified object from the collection. |
IList.RemoveAt(Int32) |
指定したインデックスの要素をコレクションから削除します。Removes the element with the specified index from the collection. |
拡張メソッド
Cast<TResult>(IEnumerable) |
IEnumerable の要素を、指定した型にキャストします。Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
指定された型に基づいて IEnumerable の要素をフィルター処理します。Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
クエリの並列化を有効にします。Enables parallelization of a query. |
AsQueryable(IEnumerable) |
IEnumerable を IQueryable に変換します。Converts an IEnumerable to an IQueryable. |