BindingList イベント


関連項目
BindingList ジェネリック クラスSystem.ComponentModel 名前空間
IBindingList
ICancelAddNew
IEditableObject
IRaiseItemChangedEvents
CurrencyManager
BindingSource
BindingList コンストラクタ ()
アセンブリ: System (system.dll 内)



新しい BindingList を構築する方法を次のコード例に示します。詳細については、BindingList クラスの概要のトピックを参照してください。
' Declare a new BindingListOfT with the Part business object. Private WithEvents listOfParts As BindingList(Of Part) Private Sub InitializeListOfParts() ' Create the new BindingList of Part type. listOfParts = New BindingList(Of Part) ' Allow new parts to be added, but not removed once committed. listOfParts.AllowNew = True listOfParts.AllowRemove = False ' Raise ListChanged events when new parts are added. listOfParts.RaiseListChangedEvents = True ' Do not allow parts to be edited. listOfParts.AllowEdit = False ' Add a couple of parts to the list. listOfParts.Add(New Part("Widget", 1234)) listOfParts.Add(New Part("Gadget", 5647)) End Sub

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


BindingList コンストラクタ

名前 | 説明 |
---|---|
BindingList () | 既定値を使用して BindingList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
BindingList (ジェネリック IList) | 指定したリストを使用して、BindingList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |

BindingList コンストラクタ (ジェネリック IList)
アセンブリ: System (system.dll 内)



Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


BindingList ジェネリック クラス
アセンブリ: System (system.dll 内)

<SerializableAttribute> _ Public Class BindingList(Of T) Inherits Collection(Of T) Implements IBindingList, IList, ICollection, IEnumerable, _ ICancelAddNew, IRaiseItemChangedEvents
[SerializableAttribute] public class BindingList<T> : Collection<T>, IBindingList, IList, ICollection, IEnumerable, ICancelAddNew, IRaiseItemChangedEvents

BindingList クラスを基本クラスとして使用して、双方向のデータ バインディング機構を作成できます。BindingList には、IBindingList インターフェイスの具体的な汎用実装が用意されています。これは、IBindingList、IEditableObject、および関連付けられた CurrencyManager 間の対話処理が複雑なために実現が難しいことがある、完全な IBindingList インターフェイスの実装の代替となります。ただし、通常のソリューション プログラマは BindingList を直接使用する代わりに、BindingSource などの、データ バインディング機能を提供するクラスを使用します。
BindingList は、拡張性のある AddNew メソッドを通じて、ファクトリ作成のインスタンスをサポートします。(これと同じ種類の拡張性は BindingSource などの他のクラスにも存在します。) また、このクラスは ICancelAddNew インターフェイスを実装しているため、EndNew メソッドと CancelNew メソッドを通じて、トランザクションで新しい項目をコミットしたりロールバックしたりできます。
![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、SharedState です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |

ビジネス オブジェクトを格納する BindingList コンポーネントにバインディングするコード例を次に示します。これは、Main メソッドを含む完全なコード例です。
Option Explicit On Option Strict On Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Drawing Imports System.Text Imports System.Windows.Forms Class Form1 Inherits Form Private textBox2 As TextBox Private listBox1 As ListBox Private WithEvents button1 As Button Private textBox1 As TextBox Private randomNumber As New Random() Public Sub New() Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.textBox1 = New System.Windows.Forms.TextBox() Me.textBox2 = New System.Windows.Forms.TextBox() Me.listBox1 = New System.Windows.Forms.ListBox() Me.button1 = New System.Windows.Forms.Button() Me.textBox1.Location = New System.Drawing.Point(169, 26) Me.textBox1.Size = New System.Drawing.Size(100, 20) Me.textBox1.Text = "Bracket" Me.textBox2.Location = New System.Drawing.Point(169, 57) Me.textBox2.ReadOnly = True Me.textBox2.Size = New System.Drawing.Size(100, 20) Me.textBox2.Text = "4343" Me.listBox1.FormattingEnabled = True Me.listBox1.Location = New System.Drawing.Point(12, 12) Me.listBox1.Size = New System.Drawing.Size(120, 95) Me.button1.Location = New System.Drawing.Point(180, 83) Me.button1.Size = New System.Drawing.Size(75, 23) Me.button1.Text = "Add New Item" Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.button1) Me.Controls.Add(Me.listBox1) Me.Controls.Add(Me.textBox2) Me.Controls.Add(Me.textBox1) Me.Text = "Parts Form" AddHandler Me.Load, AddressOf Form1_Load End Sub 'New Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) InitializeListOfParts() listBox1.DataSource = listOfParts listBox1.DisplayMember = "PartName" End Sub ' Declare a new BindingListOfT with the Part business object. Private WithEvents listOfParts As BindingList(Of Part) Private Sub InitializeListOfParts() ' Create the new BindingList of Part type. listOfParts = New BindingList(Of Part) ' Allow new parts to be added, but not removed once committed. listOfParts.AllowNew = True listOfParts.AllowRemove = False ' Raise ListChanged events when new parts are added. listOfParts.RaiseListChangedEvents = True ' Do not allow parts to be edited. listOfParts.AllowEdit = False ' Add a couple of parts to the list. listOfParts.Add(New Part("Widget", 1234)) listOfParts.Add(New Part("Gadget", 5647)) End Sub ' Create a new part from the text in the two text boxes. Private Sub listOfParts_AddingNew(ByVal sender As Object, _ ByVal e As AddingNewEventArgs) Handles listOfParts.AddingNew e.NewObject = New Part(textBox1.Text, Integer.Parse(textBox2.Text)) End Sub ' Add the new part unless the part number contains ' spaces. In that case cancel the add. Private Sub button1_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles button1.Click Dim newPart As Part = listOfParts.AddNew() If newPart.PartName.Contains(" ") Then MessageBox.Show("Part names cannot contain spaces.") listOfParts.CancelNew(listOfParts.IndexOf(newPart)) Else textBox2.Text = randomNumber.Next(9999).ToString() textBox1.Text = "Enter part name" End If End Sub <STAThread()> _ Shared Sub Main() Application.EnableVisualStyles() Application.Run(New Form1()) End Sub End Class ' A simple business object for example purposes. Public Class Part Private name As String Private number As Integer Public Sub New() End Sub Public Sub New(ByVal nameForPart As String, _ ByVal numberForPart As Integer) PartName = nameForPart PartNumber = numberForPart End Sub Public Property PartName() As String Get Return name End Get Set(ByVal value As String) name = Value End Set End Property Public Property PartNumber() As Integer Get Return number End Get Set(ByVal value As Integer) number = Value End Set End Property End Class
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; namespace BindingListOfTExamples { public partial class Form1 : Form { private TextBox textBox2; private ListBox listBox1; private Button button1; private TextBox textBox1; Random randomNumber = new Random(); public Form1() { this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.listBox1 = new System.Windows.Forms.ListBox(); this.button1 = new System.Windows.Forms.Button(); this.textBox1.Location = new System.Drawing.Point(169, 26); this.textBox1.Size = new System.Drawing.Size(100, 20); this.textBox1.Text = "Bracket"; this.textBox2.Location = new System.Drawing.Point(169, 57); this.textBox2.ReadOnly = true; this.textBox2.Size = new System.Drawing.Size(100, 20); this.textBox2.Text = "4343"; this.listBox1.FormattingEnabled = true; this.listBox1.Location = new System.Drawing.Point(12, 12); this.listBox1.Size = new System.Drawing.Size(120, 95); this.button1.Location = new System.Drawing.Point(180, 83); this.button1.Size = new System.Drawing.Size(75, 23); this.button1.Text = "Add New Item"; this.button1.Click += new System.EventHandler(this.button1_Click); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.button1); this.Controls.Add(this.listBox1); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Text = "Parts Form"; this.Load += new EventHandler(Form1_Load); } void Form1_Load(object sender, EventArgs e) { InitializeListOfParts(); listBox1.DataSource = listOfParts; listBox1.DisplayMember = "PartName"; listOfParts.AddingNew += new AddingNewEventHandler(listOfParts_AddingNew); listOfParts.ListChanged += new ListChangedEventHandler(listOfParts_ListChanged); } // Declare a new BindingListOfT with the Part business object. BindingList<Part> listOfParts; private void InitializeListOfParts() { // Create the new BindingList of Part type. listOfParts = new BindingList<Part>(); // Allow new parts to be added, but not removed once committed. listOfParts.AllowNew = true; listOfParts.AllowRemove = false; // Raise ListChanged events when new parts are added. listOfParts.RaiseListChangedEvents = true; // Do not allow parts to be edited. listOfParts.AllowEdit = false; // Add a couple of parts to the list. listOfParts.Add(new Part("Widget", 1234)); listOfParts.Add(new Part("Gadget", 5647)); } // Create a new part from the text in the two text boxes. void listOfParts_AddingNew(object sender, AddingNewEventArgs e) { e.NewObject = new Part(textBox1.Text, int.Parse(textBox2.Text)); } // Add the new part unless the part number contains // spaces. In that case cancel the add. private void button1_Click(object sender, EventArgs e) { Part newPart = listOfParts.AddNew(); if (newPart.PartName.Contains(" ")) { MessageBox.Show("Part names cannot contain spaces."); listOfParts.CancelNew(listOfParts.IndexOf(newPart)); } else { textBox2.Text = randomNumber.Next(9999).ToString(); textBox1.Text = "Enter part name"; } } void listOfParts_ListChanged(object sender, ListChangedEventArgs e) { MessageBox.Show(e.ListChangedType.ToString()); } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); } } // A simple business object for example purposes. public class Part { private string name; private int number; public Part() { } public Part(string nameForPart, int numberForPart) { PartName = nameForPart; PartNumber = numberForPart; } public string PartName { get { return name; } set { name = value; } } public int PartNumber { get { return number; } set { number = value; } } } }

System.Collections.ObjectModel.Collection
System.ComponentModel.BindingList


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


BindingList メンバ
System.ComponentModel 名前空間
IBindingList
ICancelAddNew
IEditableObject
IRaiseItemChangedEvents
CurrencyManager
BindingSource
BindingList プロパティ

名前 | 説明 | |
---|---|---|
![]() | Count | Collection に実際に格納されている要素の数を取得します。 ( Collection から継承されます。) |
![]() | Item | 指定したインデックスにある要素を取得または設定します。 ( Collection から継承されます。) |
![]() | RaiseListChangedEvents | リストの項目を追加または削除すると ListChanged イベントが発生するかどうかを示す値を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | Items | Collection をラップする List ラッパーを取得します。 ( Collection から継承されます。) |
![]() | SupportsSortingCore | リストが並べ替えをサポートしているかどうかを示す値を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | System.ComponentModel.IRaiseItemChangedEvents.RaisesItemChangedEvents | 項目のプロパティ値が変更されると、種類が ItemChanged の ListChanged イベントが発生するかどうかを示す値を取得します。このメンバは、派生クラスでオーバーライドすることはできません。 |

関連項目
BindingList ジェネリック クラスSystem.ComponentModel 名前空間
IBindingList
ICancelAddNew
IEditableObject
IRaiseItemChangedEvents
CurrencyManager
BindingSource
BindingList メソッド


名前 | 説明 | |
---|---|---|
![]() | AddNewCore | コレクションの末尾に新しい項目を追加します。 |
![]() | ApplySortCore | 派生クラスでオーバーライドされた場合は、項目を並べ替えます。それ以外の場合は NotSupportedException をスローします。 |
![]() | ClearItems | オーバーライドされます。 コレクションからすべての要素を削除します。 |
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | FindCore | 検索が派生クラスに実装されている場合、指定した値の指定したプロパティ記述子を持つ項目のインデックスを検索します。実装されていない場合は NotSupportedException がスローされます。 |
![]() | InsertItem | オーバーライドされます。 リスト内の指定したインデックス位置に、指定した項目を挿入します。 |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
![]() | OnAddingNew | AddingNew イベントを発生させます。 |
![]() | OnListChanged | ListChanged イベントを発生させます。 |
![]() | RemoveItem | オーバーライドされます。 指定したインデックスにある項目を削除します。 |
![]() | RemoveSortCore | 派生クラスで並べ替えが実装されている場合は、ApplySortCore を使用して適用された並べ替えをすべて解除します。それ以外の場合は NotSupportedException を発生させます。 |
![]() | SetItem | オーバーライドされます。 指定したインデックス位置の項目を、指定した項目で置き換えます。 |

名前 | 説明 | |
---|---|---|
![]() | System.ComponentModel.IBindingList.AddIndex | このメンバの説明については、AddIndex のトピックを参照してください。 |
![]() | System.ComponentModel.IBindingList.AddNew | リストに新しい項目を追加します。詳細については、「AddNew」を参照してください。 |
![]() | System.ComponentModel.IBindingList.ApplySort | このメンバの説明については、ApplySort のトピックを参照してください。 |
![]() | System.ComponentModel.IBindingList.Find | このメンバの説明については、Find のトピックを参照してください。 |
![]() | System.ComponentModel.IBindingList.RemoveIndex | このメンバの説明については、RemoveIndex のトピックを参照してください。 |
![]() | System.ComponentModel.IBindingList.RemoveSort | このメンバの説明については、RemoveSort のトピックを参照してください。 |

関連項目
BindingList ジェネリック クラスSystem.ComponentModel 名前空間
IBindingList
ICancelAddNew
IEditableObject
IRaiseItemChangedEvents
CurrencyManager
BindingSource
BindingList メンバ
データ バインディングをサポートしているジェネリック コレクションを提供します。
BindingList ジェネリック型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Count | Collection に実際に格納されている要素の数を取得します。(Collection から継承されます。) |
![]() | Item | 指定したインデックスにある要素を取得または設定します。(Collection から継承されます。) |
![]() | RaiseListChangedEvents | リストの項目を追加または削除すると ListChanged イベントが発生するかどうかを示す値を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | Items | Collection をラップする List ラッパーを取得します。(Collection から継承されます。) |
![]() | SupportsSortingCore | リストが並べ替えをサポートしているかどうかを示す値を取得します。 |


名前 | 説明 | |
---|---|---|
![]() | AddNewCore | コレクションの末尾に新しい項目を追加します。 |
![]() | ApplySortCore | 派生クラスでオーバーライドされた場合は、項目を並べ替えます。それ以外の場合は NotSupportedException をスローします。 |
![]() | ClearItems | オーバーライドされます。 コレクションからすべての要素を削除します。 |
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | FindCore | 検索が派生クラスに実装されている場合、指定した値の指定したプロパティ記述子を持つ項目のインデックスを検索します。実装されていない場合は NotSupportedException がスローされます。 |
![]() | InsertItem | オーバーライドされます。 リスト内の指定したインデックス位置に、指定した項目を挿入します。 |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
![]() | OnAddingNew | AddingNew イベントを発生させます。 |
![]() | OnListChanged | ListChanged イベントを発生させます。 |
![]() | RemoveItem | オーバーライドされます。 指定したインデックスにある項目を削除します。 |
![]() | RemoveSortCore | 派生クラスで並べ替えが実装されている場合は、ApplySortCore を使用して適用された並べ替えをすべて解除します。それ以外の場合は NotSupportedException を発生させます。 |
![]() | SetItem | オーバーライドされます。 指定したインデックス位置の項目を、指定した項目で置き換えます。 |


名前 | 説明 | |
---|---|---|
![]() | System.ComponentModel.IBindingList.AddIndex | このメンバの説明については、AddIndex のトピックを参照してください。 |
![]() | System.ComponentModel.IBindingList.AddNew | リストに新しい項目を追加します。詳細については、「AddNew」を参照してください。 |
![]() | System.ComponentModel.IBindingList.ApplySort | このメンバの説明については、ApplySort のトピックを参照してください。 |
![]() | System.ComponentModel.IBindingList.Find | このメンバの説明については、Find のトピックを参照してください。 |
![]() | System.ComponentModel.IBindingList.RemoveIndex | このメンバの説明については、RemoveIndex のトピックを参照してください。 |
![]() | System.ComponentModel.IBindingList.RemoveSort | このメンバの説明については、RemoveSort のトピックを参照してください。 |
![]() | System.ComponentModel.IRaiseItemChangedEvents.RaisesItemChangedEvents | 項目のプロパティ値が変更されると、種類が ItemChanged の ListChanged イベントが発生するかどうかを示す値を取得します。このメンバは、派生クラスでオーバーライドすることはできません。 |

関連項目
BindingList ジェネリック クラスSystem.ComponentModel 名前空間
IBindingList
ICancelAddNew
IEditableObject
IRaiseItemChangedEvents
CurrencyManager
BindingSource
- BindingListのページへのリンク