DataGridViewColumnCollection クラス
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
DataGridView コントロール内の DataGridViewColumn オブジェクトのコレクションを表します。
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
- 継承
- 属性
- 実装
次のコード例は、この型の使用方法を示しています。
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 プロパティを介してコントロールへの参照を保持します。
Data |
指定した DataGridViewの DataGridViewColumnCollection クラスの新しいインスタンスを初期化します。 |
Count |
コレクション内の要素の合計数を取得します。 (継承元 BaseCollection) |
Data |
コレクションが列関連の操作を実行する DataGridView を取得します。 |
Is |
コレクションが読み取り専用かどうかを示す値を取得します。 (継承元 BaseCollection) |
Is |
ICollection へのアクセスが同期されているかどうかを示す値を取得します。 (継承元 BaseCollection) |
Item[Int32] |
コレクション内の指定したインデックス位置にある列を取得または設定します。 |
Item[String] |
コレクション内の指定された名前の列を取得または設定します。 |
List |
BaseCollection インスタンスに含まれる要素の一覧を取得します。 |
Sync |
BaseCollectionへのアクセスを同期するために使用できるオブジェクトを取得します。 (継承元 BaseCollection) |
Collection |
コレクションが変更されたときに発生します。 |
ICollection. |
コレクションの内容全体を、ターゲット配列の指定したインデックスから始まる互換性のある 1 次元 Arrayにコピーします。 |
ICollection. |
コレクション内の要素の数を取得します。 |
ICollection. |
コレクションへのアクセスが同期されているかどうかを示す値を取得します。 |
ICollection. |
コレクションへのアクセスを同期するために使用できるオブジェクトを取得します。 |
IEnumerable. |
コレクションを反復処理する列挙子を返します。 |
IList. |
コレクションの末尾にオブジェクトを追加します。 |
IList. |
コレクションからすべての要素を削除します。 |
IList. |
オブジェクトがコレクション内にあるかどうかを判断します。 |
IList. |
コレクション内の特定の項目のインデックスを決定します。 |
IList. |
指定したインデックス位置にあるコレクションに要素を挿入します。 |
IList. |
コレクションのサイズが固定されているかどうかを示す値を取得します。 |
IList. |
コレクションが読み取り専用かどうかを示す値を取得します。 |
IList. |
指定したインデックス位置にある要素を取得または設定します。 |
IList. |
指定したオブジェクトの最初の出現箇所をコレクションから削除します。 |
IList. |
指定したインデックスを持つ要素をコレクションから削除します。 |
Cast<TResult>(IEnumerable) |
IEnumerable の要素を指定した型にキャストします。 |
Of |
指定した型に基づいて、IEnumerable の要素をフィルター処理します。 |
As |
クエリの並列化を有効にします。 |
As |
IEnumerable を IQueryableに変換します。 |
製品 | バージョン |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。