/// <summary>
        /// Sets up BindingSourceNode objects for all
        /// BindingSource objects related to the provided
        /// root source.
        /// </summary>
        /// <param name="container">
        /// Container for the components.
        /// </param>
        /// <param name="rootSource">
        /// Root BindingSource object.
        /// </param>
        /// <returns></returns>
        public static BindingSourceNode InitializeBindingSourceTree(
            IContainer container, BindingSource rootSource)
        {
            if (rootSource == null)
            {
                throw new ApplicationException(Resources.BindingSourceNotProvided);
            }

            _rootSourceNode = new BindingSourceNode(rootSource);
            _rootSourceNode.Children.AddRange(GetChildBindingSources(container, rootSource, _rootSourceNode));

            return(_rootSourceNode);
        }
Пример #2
0
        /// <summary>
        /// Resets all action behaviors.
        /// </summary>
        /// <param name="objectToBind">Target object.</param>
        public void ResetActionBehaviors(ISavable objectToBind)
        {
            InitializeControls(true);

            BindingSource rootSource = _dataSource as BindingSource;

            if (rootSource != null)
            {
                rootSource.CurrentItemChanged -= BusinessObject_PropertyChanged;
                rootSource.CurrentItemChanged += BusinessObject_PropertyChanged;
            }

            _bindingSourceTree = BindingSourceHelper.InitializeBindingSourceTree(_container, rootSource);
            _bindingSourceTree.Bind(objectToBind);
        }
        private static List <BindingSourceNode> GetChildBindingSources(
            IContainer container, BindingSource parent, BindingSourceNode parentNode)
        {
            List <BindingSourceNode> children = new List <BindingSourceNode>();

            foreach (Component component in container.Components)
            {
                if (component is BindingSource)
                {
                    BindingSource temp = component as BindingSource;
                    if (temp.DataSource != null && temp.DataSource.Equals(parent))
                    {
                        BindingSourceNode childNode = new BindingSourceNode(temp);
                        children.Add(childNode);
                        childNode.Children.AddRange(GetChildBindingSources(container, temp, childNode));
                        childNode.Parent = parentNode;
                    }
                }
            }

            return(children);
        }