BindingsCollection.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / BindingsCollection.cs / 1305376 / BindingsCollection.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Windows.Forms { 
 
    using System;
    using Microsoft.Win32; 
    using System.Diagnostics;
    using System.ComponentModel;
    using System.Collections;
 
    /// 
    ///  
    ///    Represents a collection of data bindings on a control. 
    /// 
    [DefaultEvent("CollectionChanged")] 
    public class BindingsCollection : System.Windows.Forms.BaseCollection {

        private ArrayList list;
        private CollectionChangeEventHandler onCollectionChanging; 
        private CollectionChangeEventHandler onCollectionChanged;
 
        // internalonly 
        internal BindingsCollection() {
        } 

        /// 
        public override int Count {
            get { 
                if (list == null) {
                    return 0; 
                } 
                return base.Count;
            } 
        }

        /// 
        ///  
        /// 
        ///     
        ///       Gets the bindings in the collection as an object. 
        ///    
        ///  
        protected override ArrayList List {
            get {
                if (list == null)
                    list = new ArrayList(); 
                return list;
            } 
        } 

        ///  
        /// 
        /// Gets the  at the specified index.
        /// 
        public Binding this[int index] { 
            get {
                return (Binding) List[index]; 
            } 
        }
 
        /// 
        // internalonly
        internal protected void Add(Binding binding) {
            CollectionChangeEventArgs ccevent = new CollectionChangeEventArgs(CollectionChangeAction.Add, binding); 
            OnCollectionChanging(ccevent);
            AddCore(binding); 
            OnCollectionChanged(ccevent); 
        }
 
        // internalonly
        /// 
        /// 
        ///  
        ///    
        ///       Adds a  
        ///       to the collection. 
        ///    
        ///  
        protected virtual void AddCore(Binding dataBinding) {
            if (dataBinding == null)
                throw new ArgumentNullException("dataBinding");
 
            List.Add(dataBinding);
        } 
 
        /// 
        ///  
        ///    
        ///       Occurs when the collection is about to change.
        ///    
        ///  
        [SRDescription(SR.collectionChangingEventDescr)]
        public event CollectionChangeEventHandler CollectionChanging { 
            add { 
                onCollectionChanging += value;
            } 
            remove {
                onCollectionChanging -= value;
            }
        } 

        ///  
        ///  
        ///    
        ///       Occurs when the collection is changed. 
        ///    
        /// 
        [SRDescription(SR.collectionChangedEventDescr)]
        public event CollectionChangeEventHandler CollectionChanged { 
            add {
                onCollectionChanged += value; 
            } 
            remove {
                onCollectionChanged -= value; 
            }
        }

        // internalonly 
        /// 
        internal protected void Clear() { 
            CollectionChangeEventArgs ccevent = new CollectionChangeEventArgs(CollectionChangeAction.Refresh, null); 
            OnCollectionChanging(ccevent);
            ClearCore(); 
            OnCollectionChanged(ccevent);
        }

        // internalonly 
        /// 
        ///  
        ///  
        ///    
        ///       Clears the collection of any members. 
        ///    
        /// 
        protected virtual void ClearCore() {
            List.Clear(); 
        }
 
        ///  
        /// 
        ///     
        ///       Raises the  event.
        ///    
        /// 
        protected virtual void OnCollectionChanging(CollectionChangeEventArgs e) { 
            if (onCollectionChanging != null) {
                onCollectionChanging(this, e); 
            } 
        }
 
        /// 
        /// 
        ///    
        ///       Raises the  event. 
        ///    
        ///  
        protected virtual void OnCollectionChanged(CollectionChangeEventArgs ccevent) { 
            if (onCollectionChanged != null) {
                onCollectionChanged(this, ccevent); 
            }
        }

        ///  
        // internalonly
        internal protected void Remove(Binding binding) { 
            CollectionChangeEventArgs ccevent = new CollectionChangeEventArgs(CollectionChangeAction.Remove, binding); 
            OnCollectionChanging(ccevent);
            RemoveCore(binding); 
            OnCollectionChanged(ccevent);
        }

 
        /// 
        // internalonly 
        internal protected void RemoveAt(int index) { 
            Remove(this[index]);
        } 

        // internalonly
        /// 
        ///  
        /// 
        ///     
        ///       Removes the specified  from the collection. 
        ///    
        ///  
        protected virtual void RemoveCore(Binding dataBinding) {
            List.Remove(dataBinding);
        }
 

        ///  
        // internalonly 
        internal protected bool ShouldSerializeMyAll() {
            return Count > 0; 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK