Exemplo n.º 1
0
        private void CreateDropDownDataSource(ICollection collection)
        {
            _listItemType = ListBindingHelper.GetListItemType(collection);

            if (typeof(ITypedList).IsAssignableFrom(collection.GetType()))
            {
                _propertyDescriptors = ((ITypedList)collection).GetItemProperties(null);
            }
            else
            {
                if (!IsGenericCollection(collection.GetType()) && collection.Count == 0)
                {
                    throw new InvalidOperationException("Unable to determine listitem type");
                }
                else
                {
                    _propertyDescriptors = TypeDescriptor.GetProperties(_listItemType);
                }
            }

            _dropDownDataSource  = new TypedArrayList(collection, _propertyDescriptors);
            _dataGrid.DataSource = _dropDownDataSource;

            if (BindingContext != null)
            {
                _currencyManager = (CurrencyManager)BindingContext[_dataGrid.DataSource];
            }
        }
Exemplo n.º 2
0
    public static void Bind(this DataGridView view, object dataSource, string dataMember = "", Func <PropertyDescriptor, DataGridViewColumn> columnFactory = null)
    {
        var columns    = new List <DataGridViewColumn>();
        var properties = ListBindingHelper.GetListItemProperties(dataSource, dataMember, null);

        for (int i = 0; i < properties.Count; i++)
        {
            var property = properties[i];
            if (!property.IsBrowsable)
            {
                continue;
            }
            var column = (columnFactory != null ? columnFactory(property) : null) ?? DefaultColumnFactory(property.PropertyType);
            if (column == null)
            {
                continue;
            }
            column.DataPropertyName = property.Name;
            column.Name             = property.Name;
            column.HeaderText       = !string.IsNullOrEmpty(property.DisplayName) ? property.DisplayName : property.Name;
            column.ValueType        = property.PropertyType;
            column.ReadOnly         = property.IsReadOnly;
            columns.Add(column);
        }
        view.DataSource = null;
        view.Columns.Clear();
        view.AutoGenerateColumns = false;
        view.Columns.AddRange(columns.ToArray());
        view.DataMember = dataMember;
        view.DataSource = dataSource;
    }
Exemplo n.º 3
0
        private void radGridView1_UserDeletedRow(object sender, GridViewRowEventArgs e)
        {
            GridViewRowInfo[] rows = e.Rows;
            for (int i = 0; i < (int)rows.Length; i++)
            {
                GridViewRowInfo row = rows[i];
                if (row.HierarchyLevel != 0)
                {
                    GridViewRelation             relation         = this.radGridView1.Relations.Find(row.ViewTemplate.Parent, row.ViewTemplate);
                    GridViewRowInfo              parentRow        = row.Parent as GridViewRowInfo;
                    PropertyDescriptorCollection parentProperties = ListBindingHelper.GetListItemProperties(parentRow.DataBoundItem);
                    PropertyDescriptor           childDescriptor  = parentProperties.Find(relation.ChildColumnNames[0], true);
                    if (childDescriptor != null)
                    {
                        IList children = childDescriptor.GetValue(parentRow.DataBoundItem) as IList;
                        if (children != null)
                        {
                            children.Remove(row.DataBoundItem);
                            row.ViewInfo.Refresh();

                            foreach (var childRow in row.ViewInfo.ChildRows)
                            {
                                childRow.InvalidateRow();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        ///<summary>Sets the owning edit's DataSource.  This method must be called when initialization is complete.</summary>
        void SetEditorData()
        {
            if (IsLoading || OwnerEdit == null || OwnerEdit.BindingContext == null)
            {
                return;
            }
            if (DataSource == null)
            {
                OwnerEdit.AllItems = new object[0];
                return;
            }

            ResultsBindingManager = OwnerEdit.BindingContext[DataSource, DataMember];
            ItemProperties        = ResultsBindingManager.GetItemProperties();
            OwnerEdit.AllItems    = (IList)ListBindingHelper.GetList(DataSource, DataMember);
            Columns.OnDataSourceSet();
            AdditionalResultColumns.OnDataSourceSet();
            if (ResultDisplayColumn != null)
            {
                ResultDisplayColumn.SetOwner(this);
            }
            if (SortColumn != null)
            {
                SortColumn.SetOwner(this);
            }
        }
Exemplo n.º 5
0
        protected override object QueryResultValue()
        {
            string currentValue = String.Empty;

            try {
                IList list = ListBindingHelper.GetList(this.OwnerEdit.Properties.DataSource) as IList;
                PropertyDescriptorCollection pdc = ListBindingHelper.GetListItemProperties(this.OwnerEdit.Properties.DataSource);
                PropertyDescriptor           pd  = pdc[this.OwnerEdit.Properties.Columns[this.OwnerEdit.Properties.AutoSearchColumnIndex].FieldName];
                currentValue = pd.GetValue(list[selectedRowIndex]).ToString();
            } catch { }
            if (!this.OwnerEdit.Properties.CaseSensitiveSearch)
            {
                currentValue = currentValue.ToLower();
                this.IncrementalSearchText = this.IncrementalSearchText.ToLower();
            }
            if (this.IncrementalSearchText == "" || currentValue.StartsWith(this.IncrementalSearchText))
            {
                this.IncrementalSearchText = "";
                return(base.QueryResultValue());
            }
            else
            {
                this.IncrementalSearchText = "";
                return(base.QueryOldEditValue());
            }
        }
Exemplo n.º 6
0
        public void TryDataBinding()
        {
            int i;
            PropertyDescriptorCollection pc = null;

            if (this.DataSource != null)
            {
                pc = ListBindingHelper.GetListItemProperties(this.DataSource);
            }
            if (pc == null)
            {
                CurrencyManager cm = this.DataManager;
                if (cm != null)
                {
                    pc = cm.GetItemProperties();
                }
            }
            if (pc == null)
            {
                pc = ListBindingHelper.GetListItemProperties(this.Items);
            }
            if (pc != null)
            {
                m_ColumnNamesAll = new string[pc.Count];
                for (i = 0; i < m_ColumnNamesAll.Length; i++)
                {
                    m_ColumnNamesAll[i] = pc[i].Name.ToLower();
                }
            }
            CheckColumns();
            CheckColumnIndexes();
        }
Exemplo n.º 7
0
 private PropertyDescriptorCollection BindToInterface(
     CurrencyManager currencyManager)
 {
     System.Type listItemType = ListBindingHelper.GetListItemType((object)this.currencyManager.List);
     if ((object)listItemType != null && listItemType.IsInterface && (!(listItemType is ITypedList) && this.currencyManager.List.Count > 0))
     {
         if (this.currencyManager.List.Count == 1)
         {
             return(TypeDescriptor.GetProperties(this.currencyManager.List[0]));
         }
         bool flag = true;
         for (int index = 1; index < this.currencyManager.List.Count; ++index)
         {
             if ((object)this.currencyManager.List[0].GetType() != (object)this.currencyManager.List[index].GetType())
             {
                 flag = false;
                 break;
             }
         }
         if (flag)
         {
             return(TypeDescriptor.GetProperties(this.currencyManager.List[0]));
         }
     }
     return((PropertyDescriptorCollection)null);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Returns the data type of the items in the specified list.
        /// </summary>
        /// <param name="enumerable">The enumerable to be examined for type information.</param>
        /// <returns>The System.Type of the items contained in the list.</returns>
        public static Type GetEnumerableItemType(IEnumerable enumerable)
        {
            var queryable = enumerable as IQueryable;

            if (queryable != null)
            {
                return(queryable.ElementType);
            }
            Type itemType;

            try
            {
                itemType = ListBindingHelper.GetListItemType(enumerable);
            }
            catch (NotImplementedException)
            {
                itemType = null;
            }
            if (itemType == null || itemType == typeof(object))
            {
                var enumerableType = enumerable.GetType();
                var elementType    = GetElementType(enumerableType);
                if (elementType != enumerableType)
                {
                    return(elementType);
                }
                //queryable = enumerable.AsQueryable();
                //return queryable.ElementType;
            }
            return(itemType);
        }
Exemplo n.º 9
0
        private void SetProperty(ref PropertyDescriptor property, ref string propertyName, string value)
        {
            if (propertyName != value)
            {
                if (value == null)
                {
                    DataMember   = string.Empty;
                    propertyName = string.Empty;
                }
                else
                {
                    var    split = value.Split(_dataMemberFieldSeperator);
                    string temp;
                    if (split.Length > 1)
                    {
                        DataMember = split[0];
                        temp       = split[1];
                    }
                    else
                    {
                        DataMember = string.Empty;
                        temp       = value;
                    }
                    propertyName = null;
                    if (DataSource != null && temp != string.Empty)
                    {
                        var propertyDescriptorCollection = ListBindingHelper.GetListItemProperties(DataSource, DataMember, null);
                        if (propertyDescriptorCollection != null)
                        {
                            if (propertyDescriptorCollection.Count == 0)
                            {
                                propertyName = value;
                            }
                            else
                            {
                                property = propertyDescriptorCollection.Find(temp, true);
                                if (property == null && _fieldsToPropertiesTypeDescriptionProvider == null)
                                {
                                    _fieldsToPropertiesTypeDescriptionProvider = new FieldsToPropertiesTypeDescriptionProvider(propertyDescriptorCollection[0].ComponentType, BindingFlags.Instance | BindingFlags.Public);
                                    TypeDescriptor.AddProvider(_fieldsToPropertiesTypeDescriptionProvider, propertyDescriptorCollection[0].ComponentType);
                                    propertyDescriptorCollection = ListBindingHelper.GetListItemProperties(DataSource, DataMember, null);
                                    property = propertyDescriptorCollection.Find(temp, true);
                                }
                            }
                        }

                        if (property != null)
                        {
                            propertyName = value;
                        }
                    }
                    else
                    {
                        propertyName = value;
                    }
                }
            }
            //  this.ResetData();
        }
 private void InitializeFiltering()
 {
     _properties  = ListBindingHelper.GetListItemProperties(typeof(T));
     _filterTable = new DataTable("FilterTable");
     foreach (PropertyDescriptor property in _properties)
     {
         _filterTable.Columns.Add(property.Name, property.PropertyType);
     }
 }
Exemplo n.º 11
0
 private static IBindingListView ToObjectListView <T>(this IEnumerable <T> enumerable)
 {
     if (typeof(T) == typeof(string))
     {
         return(null);
     }
     enumerable = (IEnumerable <T>)ListBindingHelper.GetList(enumerable);
     return(ToObjectListView((IList <T>)enumerable.ToList()));
 }
Exemplo n.º 12
0
 public SortedBindingList(IList <T> list) : base(list)
 {
     foreach (var _val in list)
     {
         this._collection.Add(_val);
     }
     this._properties  = ListBindingHelper.GetListItemProperties(typeof(T));
     this.ListChanged += this._listChanged;
 }
Exemplo n.º 13
0
        protected void UpdateDataPropertiesCache()
        {
            if (this.currencyManager == null)
            {
                return;
            }

            this.dataItemProperties = ListBindingHelper.GetListItemProperties(this.currencyManager.List);
        }
Exemplo n.º 14
0
        public void GetListItemPropertiesTest()
        {
            SimpleItem [] items = new SimpleItem [0];
            PropertyDescriptorCollection properties = ListBindingHelper.GetListItemProperties(items);

            Assert.AreEqual(1, properties.Count, "#A1");
            Assert.AreEqual("Value", properties [0].Name, "#A2");

            List <SimpleItem> items_list = new List <SimpleItem> ();

            properties = ListBindingHelper.GetListItemProperties(items_list);

            Assert.AreEqual(1, properties.Count, "#B1");
            Assert.AreEqual("Value", properties [0].Name, "#B2");

            // Empty arraylist
            ArrayList items_arraylist = new ArrayList();

            properties = ListBindingHelper.GetListItemProperties(items_arraylist);

            Assert.AreEqual(0, properties.Count, "#C1");

            // Non empty arraylist
            items_arraylist.Add(new SimpleItem());
            properties = ListBindingHelper.GetListItemProperties(items_arraylist);

            Assert.AreEqual(1, properties.Count, "#D1");
            Assert.AreEqual("Value", properties [0].Name, "#D2");

            // non list object
            properties = ListBindingHelper.GetListItemProperties(new SimpleItem());

            Assert.AreEqual(1, properties.Count, "#E1");
            Assert.AreEqual("Value", properties [0].Name, "#E2");

            // null value
            properties = ListBindingHelper.GetListItemProperties(null);

            Assert.AreEqual(0, properties.Count, "#F1");

            // ListSource
            properties = ListBindingHelper.GetListItemProperties(new ListSource(true));

            Assert.AreEqual(1, properties.Count, "#G1");
            Assert.AreEqual("Value", properties [0].Name, "#G2");

            // ITypedList
            DataTable table = new DataTable();

            table.Columns.Add("Name", typeof(string));

            properties = ListBindingHelper.GetListItemProperties(table);
            Assert.AreEqual(1, properties.Count, "#H1");
            Assert.AreEqual("Name", properties [0].Name, "#H2");
        }
Exemplo n.º 15
0
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            var properties = ListBindingHelper.GetListItemProperties(source, listAccessors);

            if (propertyMapper != null)
            {
                properties = new PropertyDescriptorCollection(properties.Cast <PropertyDescriptor>()
                                                              .Select(propertyMapper).Where(p => p != null).ToArray());
            }
            return(properties);
        }
Exemplo n.º 16
0
        public static int Delete(object dataToDelete, IDataAccessAdapter dataAccessAdapter)
        {
            var listItemType = ListBindingHelper.GetListItemType(dataToDelete);

            if (typeof(IEntity2).IsAssignableFrom(listItemType))
            {
                var enumerable = dataToDelete as IEnumerable;
                return(enumerable == null?Convert.ToInt32(dataAccessAdapter.DeleteEntity((IEntity2)dataToDelete)) : DeleteEntities(enumerable, dataAccessAdapter));
            }
            return(0);
        }
Exemplo n.º 17
0
        public PropertyDescriptorCollection GetItemProperties(
            PropertyDescriptor[] listAccessors)
        {
            object list = ListBindingHelper.GetList(this.dataSource);

            if (list is ITypedList && !string.IsNullOrEmpty(this.dataMember))
            {
                return(ListBindingHelper.GetListItemProperties(list, this.dataMember, listAccessors));
            }
            return(ListBindingHelper.GetListItemProperties((object)this.items, listAccessors));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Saves any changes to the specified data to the DB.
        /// </summary>
        /// <param name="dataToSave">The data to save, must be a CommonEntityBase or a list of CommonEntityBase's.</param>
        /// <returns>The number of persisted entities.</returns>
        public static int Save(object dataToSave)
        {
            var listItemType = ListBindingHelper.GetListItemType(dataToSave);

            if (typeof(IEntity).IsAssignableFrom(listItemType))
            {
                var enumerable = dataToSave as IEnumerable;
                return(enumerable == null?Convert.ToInt32(((IEntity)dataToSave).Save()) : SaveEntities(enumerable));
            }
            return(0);
        }
Exemplo n.º 19
0
        public void GetListNameTest()
        {
            List <int> list = new List <int> ();

            int []     arr  = new int [0];
            SimpleItem item = new SimpleItem();

            Assert.AreEqual(typeof(int).Name, ListBindingHelper.GetListName(list, null), "1");
            Assert.AreEqual(typeof(int).Name, ListBindingHelper.GetListName(arr, null), "2");
            Assert.AreEqual(typeof(SimpleItem).Name, ListBindingHelper.GetListName(item, null), "3");
            Assert.AreEqual(String.Empty, ListBindingHelper.GetListName(null, null), "4");
        }
Exemplo n.º 20
0
Arquivo: Row.cs Projeto: windygu/haina
 public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
 {
     if ((listAccessors != null) && (listAccessors.Length >= 1))
     {
         return(ListBindingHelper.GetListItemProperties(listAccessors[0].PropertyType));
     }
     if (this.FieldNames != null)
     {
         return(this.FieldNames.GetRowPropertyDescriptors());
     }
     return(null);
 }
Exemplo n.º 21
0
        private void CreatePropertyDescriptors()
        {
            //Clear the previous list of property descriptors
            _propertyDescriptors.Clear();

            //Get the type of object that this bindingsource is bound to

            Type itemType = ListBindingHelper.GetListItemType(DataSource, DataMember);

            PropertyDescriptorCollection originalProperites = TypeDescriptor.GetProperties(itemType);

            //Check to see if there are any bindable properties defined.
            if (BindableProperties.Count == 0)
            {
                foreach (PropertyDescriptor propertyDescriptor in originalProperites)
                {
                    Attribute[] attributes = new Attribute[propertyDescriptor.Attributes.Count];
                    propertyDescriptor.Attributes.CopyTo(attributes, 0);

                    _propertyDescriptors.Add(
                        new CustomPropertyDescriptor(propertyDescriptor.Name, ReflectionHelper.GetPropertyDescriptorFromPath(itemType, propertyDescriptor.Name), attributes, false));
                }
            }
            else
            {
                try
                {
                    foreach (BindableProperty bindableProperty in _bindableProperties)
                    {
                        //Get the original propertydescriptor based on the property path in bindableProperty
                        PropertyDescriptor propertyDescriptor = ReflectionHelper.GetPropertyDescriptorFromPath(itemType, bindableProperty.Name);
                        //Create a attribute array and make room for one more attribute
                        Attribute[] attributes = new Attribute[propertyDescriptor.Attributes.Count + 1];
                        //Copy the original attributes to the custom descriptor
                        propertyDescriptor.Attributes.CopyTo(attributes, 0);
                        //Create a new attrute preserving information about the original property.
                        attributes[attributes.Length - 1] = new CustomPropertyAttribute(itemType, bindableProperty.Name, propertyDescriptor);
                        //Finally add the new custom property descriptor to the list of property descriptors
                        _propertyDescriptors.Add(new CustomPropertyDescriptor(bindableProperty.Name, propertyDescriptor, attributes, _autoCreateObjects));
                    }
                }
                catch
                {
                    //Something is wrong in the property path of one or more properties
                    _bindableProperties.Clear();
                }
            }

            _createProperties = false;
            ResetBindings(true);
        }
Exemplo n.º 22
0
        private void lookUpEditSubLinea_Properties_PopupFilter(object sender, DevExpress.XtraEditors.Controls.PopupFilterEventArgs e)
        {
            if (string.IsNullOrEmpty(e.SearchText))
            {
                return;
            }
            LookUpEdit edit = sender as LookUpEdit;
            PropertyDescriptorCollection   propertyDescriptors = ListBindingHelper.GetListItemProperties(edit.Properties.DataSource);
            IEnumerable <FunctionOperator> operators           = propertyDescriptors.OfType <PropertyDescriptor>().Select(
                t => new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty(t.Name), new OperandValue(e.SearchText)));

            e.Criteria = new GroupOperator(GroupOperatorType.Or, operators);
            e.SuppressSearchCriteria = true;
        }
Exemplo n.º 23
0
 protected virtual void Initialize()
 {
     if (this.list is ITypedList)
     {
         this.properties = ((ITypedList)this.list).GetItemProperties((PropertyDescriptor[])null);
         this.name       = ((ITypedList)this.list).GetListName((PropertyDescriptor[])null);
     }
     else if (this.list is IEnumerable)
     {
         this.properties = ListBindingHelper.GetListItemProperties(this.list);
         this.name       = ListBindingHelper.GetListName(this.list, (PropertyDescriptor[])null);
     }
     this.BuildChildren(this);
 }
Exemplo n.º 24
0
        public void UpdateBoundProperties()
        {
            object sourceControl = this.SourceControl;

            this.boundProperties = ListBindingHelper.GetListItemProperties(this.SourceControl);
            PropertyDescriptor[] propertyDescriptorArray = new PropertyDescriptor[this.boundProperties.Count];
            this.boundProperties.CopyTo((Array)propertyDescriptorArray, 0);
            foreach (PropertyDescriptor propertyDescriptor in propertyDescriptorArray)
            {
                if ((object)propertyDescriptor.PropertyType == (object)typeof(IBindingList))
                {
                    this.boundProperties.Remove(propertyDescriptor);
                }
            }
        }
Exemplo n.º 25
0
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            PropertyDescriptorCollection pdc;

            if (listAccessors != null && listAccessors.Length > 0)
            {
                pdc = ListBindingHelper.GetListItemProperties(listAccessors[0].PropertyType);
            }
            else
            {
                pdc = properties;
            }

            return(pdc);
        }
Exemplo n.º 26
0
        protected override void Initialize()
        {
            this.parentRelationNames = new List <string>();
            this.childRelationNames  = new List <string>();

            DataTable table = this.List as DataTable;

            if (table == null && this.List is DataView)
            {
                table = ((DataView)this.List).Table;
            }

            if (table == null)
            {
                return;
            }

            this.Properties = ListBindingHelper.GetListItemProperties(table);
            this.Name       = table.TableName;

            for (int i = 0; i < table.ChildRelations.Count; i++)
            {
                DataTable childTable = table.ChildRelations[i].ChildTable;

                if (childTable == table)
                {
                    this.ChildRelations.Add(new SelfReferenceRelation(childTable,
                                                                      table.ChildRelations[i].ParentColumns[0].ColumnName,
                                                                      table.ChildRelations[i].ChildColumns[0].ColumnName));
                }
                else
                {
                    DataSetObjectRelation child = new DataSetObjectRelation(childTable);
                    child.Parent = this;

                    for (int j = 0; j < table.ChildRelations[i].ParentColumns.Length; j++)
                    {
                        child.parentRelationNames.Add(table.ChildRelations[i].ParentColumns[j].ColumnName);
                    }

                    for (int j = 0; j < table.ChildRelations[i].ChildColumns.Length; j++)
                    {
                        child.childRelationNames.Add(table.ChildRelations[i].ChildColumns[j].ColumnName);
                    }
                    this.ChildRelations.Add(child);
                }
            }
        }
        void MyGridLookUpEdit_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            PropertyDescriptorCollection collection = ListBindingHelper.GetListItemProperties(Properties.GridSelection.Selection);
            PropertyDescriptor           desc       = collection[Properties.DisplayMember];

            foreach (object rv in Properties.GridSelection.Selection)
            {
                if (sb.ToString().Length > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(desc.GetValue(rv).ToString());
            }
            e.DisplayText = sb.ToString();
        }
Exemplo n.º 28
0
 private void SetConstaintsFromDataSource()
 {
     if (this.ownerControl.DataBindings[this.ownerBindingPropertyName] == null)
     {
         PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(this.ownerControl)[this.ownerBindingPropertyName];
         if (propertyDescriptor != null)
         {
             object value        = propertyDescriptor.GetValue(this.ownerControl);
             Type   listItemType = ListBindingHelper.GetListItemType(value);
             if (null != listItemType)
             {
                 this.SetConstraintsFromType(listItemType, new PropertyDefinitionConstraint[0]);
             }
         }
     }
 }
Exemplo n.º 29
0
 int System.Collections.IComparer.Compare(object x, object y)
 {
     if (x is ListViewItem && y is ListViewItem)
     {
         return(Compare((ListViewItem)x, (ListViewItem)y));
     }
     if (x.GetType() == y.GetType())
     {
         var props = ListBindingHelper.GetListItemProperties(x);
         if (props != null && props.Count > SortColumn)
         {
             return(AdjustCompareForOrder(ObjectCompare.Compare(props[SortColumn].GetValue(x), props[SortColumn].GetValue(y))));
         }
     }
     return(ObjectCompare.Compare(x, y));
 }
Exemplo n.º 30
0
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            PropertyDescriptorCollection pdc;

            if (null == listAccessors)
            {
                /* Return properties in sort order */
                pdc = _shape;
            }
            else
            {
                /* Return child list shape */
                pdc = ListBindingHelper.GetListItemProperties(listAccessors[0].PropertyType);
            }
            return(pdc);
        }