Ejemplo n.º 1
0
// <Snippet1>
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"];
}
Ejemplo n.º 2
0
        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 the navigation path: TableName.ColumnName. */
            Binding b1 = new Binding("Text", _dataset, "customers.CompanyName");

            textBox1.DataBindings.Add(b1);
            Binding b2 = new Binding("Text", _dataset, "customers.CustomerID");

            textBox2.DataBindings.Add(b2);

            // Bind the DateTimePicker control by adding a new Binding.
            // The data member of the DateTimePicker is a navigation path: TableName.RelationName.ColumnName.
            Binding b3 = new Binding("Value", _dataset, "customers.CustToOrders.OrderDate");

            dateTimePicker1.DataBindings.Add(b3);

            //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 b4 = new Binding("Text", _dataset, "customers.custToOrder Details.Quantity");

            b4.Parse  += B4_Parse;
            b4.Format += B4_Format;
            textBox3.DataBindings.Add(b4);

            //Bind the fourth TextBox to the Value of the DateTimePicker control.
            //This demonstates how one control can be data-bound to another.
            textBox4.DataBindings.Add("Text", dateTimePicker1, "Value");

            // Get the BindingManagerBase for the textBox4 Binding.
            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 one.
            Console.WriteLine(bmText.Count);

            // Get the BindingManagerBase for the Customers table.
            var bmCustomers = this.BindingContext[_dataset, "Customers"];

            // Print the Type and count of the BindingManagerBase.
            //Because the data source inherits from IBindingList,it is a RelatedCurrencyManager (a derived class of
            //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. */
            var bmOrders = this.BindingContext[_dataset, "customers.CustToOrders"];
        }
        public void TestMemberNoEvent()
        {
            TestClass2     test = new TestClass2();
            BindingContext bc   = new BindingContext();

            BindingManagerBase bm = bc[test];

            Assert.IsTrue(typeof(PropertyManager).IsAssignableFrom(bm.GetType()), "A1");

            bm.CurrentChanged += new EventHandler(OnCurrentChanged);

            currentChangedRaised = positionChangedRaised = false;
            test.Property        = 5;
            Assert.IsFalse(currentChangedRaised, "A2");
            Assert.IsFalse(positionChangedRaised, "A3");
        }