Example #1
0
        public void Remove(object obj)
        {
            Debug.Assert(obj != null, "obj为null");

            if (obj == null)
            {
                return;
            }

            if (_currentCodon == null)
            {
                return;
            }

            IBindingListEx bindingList = GetBindingList(_currentCodon);

            if (bindingList == null)
            {
                return;
            }

            Debug.Assert(bindingList.Contains(obj), "_bindingList中没有指定对象");

            if (bindingList.Contains(obj) == false)
            {
                return;
            }

            if (_currentCodon.Compatible(obj))
            {
                bindingList.Remove(obj);
            }
        }
Example #2
0
        public void Add(object obj)
        {
            Debug.Assert(obj != null, "obj为null");

            if (obj == null)
            {
                return;
            }

            if (_currentCodon == null)
            {
                return;
            }

            IBindingListEx bindingList = GetBindingList(_currentCodon);

            if (bindingList != null && bindingList.Contains(obj))
            {
                Debug.Assert(false, "_bindingList中已经存在了指定对象");
                return;
            }

            if (_currentCodon.Compatible(obj))
            {
                //如果调用了Clear之后没有Show新的数据,那么_bindingList是为null的
                //如果调用DataBind时list中没有元素,也不会初始化_bindingList,因为BindingList需要用内部元素作类型推导
                if (bindingList == null)
                {
                    bindingList = _currentCodon.InitializeBindingList();
                    if (IsSpecialBindingList(_currentCodon))
                    {
                        AllotBindingList(_currentCodon, bindingList);
                    }
                }

                bindingList.Add(obj);

                if (_dataGridView.DataSource == null)
                {
                    _dataGridView.DataSource = bindingList;
                }
            }
        }