Control.DataBindings 속성
업데이트: 2007년 11월
컨트롤에 대한 데이터 바인딩을 가져옵니다.
어셈블리: System.Windows.Forms(System.Windows.Forms.dll)
/** @property */ public final ControlBindingsCollection get_DataBindings()
public final function get DataBindings () : ControlBindingsCollection
속성 값
형식: System.Windows.Forms.ControlBindingsCollection컨트롤의 Binding 개체를 포함하는 ControlBindingsCollection입니다.
구현
IBindableComponent.DataBindingsDataBindings 속성을 사용하여 ControlBindingsCollection에 액세스합니다. 컬렉션에 Binding 개체를 추가하면 개체의 속성에 컨트롤의 모든 속성을 바인딩할 수 있습니다.
다음 코드 예제에서는 네 개의 TextBox 컨트롤과 하나의 DateTimePicker 컨트롤의 ControlBindingsCollection에 Binding 개체를 추가합니다. ControlBindingsCollection에는 Control 클래스의 DataBindings 속성을 통해 액세스합니다.
protected void BindControls() { /* Create two Binding objects for the first two TextBox controls. The data-bound property for both controls is the Text property. The data source is a DataSet (ds). The data member is specified by a navigation path in the form : TableName.ColumnName. */ textBox1.DataBindings.Add(new Binding ("Text", ds, "customers.custName")); textBox2.DataBindings.Add(new Binding ("Text", ds, "customers.custID")); /* Bind the DateTimePicker control by adding a new Binding. The data member of the DateTimePicker is specified by a navigation path in the form: TableName.RelationName.ColumnName. */ DateTimePicker1.DataBindings.Add(new Binding("Value", ds, "customers.CustToOrders.OrderDate")); /* Create a new Binding using the DataSet and a navigation path(TableName.RelationName.ColumnName). Add event delegates for the Parse and Format events to the Binding object, and add the object to the third TextBox control's BindingsCollection. The delegates must be added before adding the Binding to the collection; otherwise, no formatting occurs until the Current object of the BindingManagerBase for the data source changes. */ Binding b = new Binding ("Text", ds, "customers.custToOrders.OrderAmount"); b.Parse += new ConvertEventHandler(CurrencyStringToDecimal); b.Format += new ConvertEventHandler(DecimalToCurrencyString); textBox3.DataBindings.Add(b); /*Bind the fourth TextBox to the Value of the DateTimePicker control. This demonstrates how one control can be bound to another.*/ textBox4.DataBindings.Add("Text", DateTimePicker1,"Value"); BindingManagerBase bmText = this.BindingContext[ DateTimePicker1]; /* Print the Type of the BindingManagerBase, which is a PropertyManager because the data source returns only a single property value. */ Console.WriteLine(bmText.GetType().ToString()); // Print the count of managed objects, which is 1. Console.WriteLine(bmText.Count); // Get the BindingManagerBase for the Customers table. bmCustomers = this.BindingContext [ds, "Customers"]; /* Print the Type and count of the BindingManagerBase. Because the data source inherits from IBindingList, it is a RelatedCurrencyManager (derived from CurrencyManager). */ Console.WriteLine(bmCustomers.GetType().ToString()); Console.WriteLine(bmCustomers.Count); /* Get the BindingManagerBase for the Orders of the current customer using a navigation path: TableName.RelationName. */ bmOrders = this.BindingContext[ds, "customers.CustToOrders"]; }
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.