コード例 #1
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());
            }
        }
コード例 #2
0
ファイル: ItemSelector.cs プロジェクト: zeroxist/Libraries
        ///<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);
            }
        }
コード例 #3
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()));
 }
コード例 #4
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));
        }
コード例 #5
0
        /// <summary>
        /// Parses a formatted value from the editing control.
        /// This works by matching the editing control's text against the
        /// display values for the list items.
        /// </summary>
        /// <param name="formattedValue"></param>
        /// <param name="cellStyle"></param>
        /// <param name="formattedValueTypeConverter"></param>
        /// <param name="valueTypeConverter"></param>
        /// <returns></returns>
        public override object ParseFormattedValue(object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter)
        {
            if (DataSource != null)
            {
                object listItem = null;
                Func <object, String> dispFormatter;

                if (!String.IsNullOrEmpty(DisplayMember))
                {
                    PropertyDescriptor pd = ListBindingHelper.GetListItemProperties(DataSource)[DisplayMember];
                    dispFormatter = o => Convert.ToString(pd.GetValue(o));
                }
                else
                {
                    dispFormatter = o => Convert.ToString(o);
                }

                foreach (object item in (IList)ListBindingHelper.GetList(DataSource))
                {
                    if (String.Compare(Convert.ToString(formattedValue), dispFormatter(item), true, CultureInfo.CurrentCulture) == 0)
                    {
                        listItem = item;
                        break;
                    }
                }

                if ((listItem != null) && !(listItem is DBNull))
                {
                    Func <object, object> valueFormatter;

                    if (!String.IsNullOrEmpty(ValueMember))
                    {
                        PropertyDescriptor pd = ListBindingHelper.GetListItemProperties(DataSource)[ValueMember];
                        valueFormatter = o => pd.GetValue(o);
                    }
                    else
                    {
                        valueFormatter = o => o;
                    }

                    return(valueFormatter(listItem));
                }
            }

            return(null);
        }
コード例 #6
0
ファイル: ObjectRelation.cs プロジェクト: RichardHaggard/BDC
 public static ObjectRelation GetObjectRelation(
     object dataSource,
     string dataMember)
 {
     if (dataSource is BindingSource)
     {
         if (((BindingSource)dataSource).DataSource == null && !string.IsNullOrEmpty(dataMember))
         {
             return((ObjectRelation)null);
         }
         if (((BindingSource)dataSource).DataSource is DataSet && !string.IsNullOrEmpty(dataMember))
         {
             dataSource = ((BindingSource)dataSource).DataSource;
         }
     }
     return(ObjectRelation.GetObjectRelation(ListBindingHelper.GetList(dataSource, dataMember)));
 }
コード例 #7
0
    public static IList Create(object dataSource, string dataMember, Func <PropertyDescriptor, PropertyDescriptor> propertyMapper)
    {
        var source = (IList)ListBindingHelper.GetList(dataSource, dataMember);

        if (source == null)
        {
            return(null);
        }
        if (source is IBindingListView)
        {
            return(new BindingListView((IBindingListView)source, propertyMapper));
        }
        if (source is IBindingList)
        {
            return(new BindingList((IBindingList)source, propertyMapper));
        }
        return(new List(source, propertyMapper));
    }
コード例 #8
0
        private static IBindingListView ToObjectListView(this IEnumerable enumerable)
        {
            var itemType = MetaDataHelper.GetEnumerableItemType(enumerable);

            if (itemType == typeof(string))
            {
                return(null);
            }
            enumerable = (IEnumerable)ListBindingHelper.GetList(enumerable);
            if (enumerable is IList)
            {
                var objectListView = ((IList)enumerable).ToObjectListView();
                if (objectListView != null)
                {
                    return(objectListView);
                }
            }
            return(CreateObjectListViewViaBindingSource(enumerable));
        }
コード例 #9
0
        /// <summary>
        /// Gets the formatted value for the cell.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="rowIndex"></param>
        /// <param name="cellStyle"></param>
        /// <param name="valueTypeConverter"></param>
        /// <param name="formattedValueTypeConverter"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
        {
            if (DataSource != null)
            {
                object listItem = null;

                if (!String.IsNullOrEmpty(ValueMember))
                {
                    PropertyDescriptor pd = ListBindingHelper.GetListItemProperties(DataSource)[ValueMember];
                    foreach (object item in (IList)ListBindingHelper.GetList(DataSource))
                    {
                        if (Object.Equals(value, pd.GetValue(item)))
                        {
                            listItem = item;
                            break;
                        }
                    }
                }
                else
                {
                    listItem = value;
                }

                if (!String.IsNullOrEmpty(DisplayMember))
                {
                    PropertyDescriptor pd = ListBindingHelper.GetListItemProperties(DataSource)[DisplayMember];
                    return(pd.GetValue(listItem));
                }
                else
                {
                    return(Convert.ToString(listItem));
                }
            }

            return(String.Empty);
        }
コード例 #10
0
 internal ObjectRelation(object dataSource, string dataMember)
     : this(ListBindingHelper.GetList(dataSource, dataMember))
 {
 }
コード例 #11
0
 public static ObjectRelation GetObjectRelation(object dataSource, string dataMember)
 {
     return(ObjectRelation.GetObjectRelation(ListBindingHelper.GetList(dataSource, dataMember)));
 }
コード例 #12
0
        public void GetListTest()
        {
            ListSource lsource = new ListSource(true);
            Stack      stack   = new Stack();

            stack.Push(3);

            Assert.IsTrue(ListBindingHelper.GetList(lsource) is SimpleItem [], "#A1");
            Assert.AreEqual("NonList", ListBindingHelper.GetList("NonList"), "#A2");
            Assert.AreEqual(null, ListBindingHelper.GetList(null), "#A3");
            Assert.AreEqual(stack, ListBindingHelper.GetList(stack), "#A4"); // IEnumerable

            Assert.IsTrue(ListBindingHelper.GetList(lsource, String.Empty) is SimpleItem [], "#B1");
            Assert.AreEqual("NonList", ListBindingHelper.GetList("NonList", String.Empty), "#B2");
            Assert.AreEqual(null, ListBindingHelper.GetList(null, "DontExist"), "#B3");
            Assert.IsTrue(ListBindingHelper.GetList(lsource, null) is SimpleItem [], "#B4");

            ListContainer list_container = new ListContainer();

            Assert.AreEqual(new object [0], ListBindingHelper.GetList(list_container, "List"), "#C1");

            // Even if IListSource.ContainsListCollection is false, we return the result of GetList ()
            lsource = new ListSource(false);
            Assert.IsTrue(ListBindingHelper.GetList(lsource) is SimpleItem [], "#D1");

            // DataMember is not if IList type
            Assert.AreEqual(new SimpleItem(), ListBindingHelper.GetList(list_container, "NonList"), "#E1");

            // List (IEnumerable)
            stack.Clear();
            stack.Push(new SimpleItem(3));
            stack.Push(new SimpleItem(7));
            object obj = ListBindingHelper.GetList(stack, "Value");

            Assert.IsTrue(obj != null, "#F1");
            Assert.IsTrue(obj is int, "#F2");
            Assert.AreEqual(7, (int)obj, "#F3");

            // ListSource returning an IEnumerable,
            // which in turn retrieves dataMember
            obj = ListBindingHelper.GetList(lsource, "Value");
            Assert.IsTrue(obj != null, "#G1");
            Assert.IsTrue(obj is int, "#G2");
            Assert.AreEqual(0, (int)obj, "#G3");

            // Empty IEnumerable - valid property for list item type
            // Since it's empty, it needs to check whether the datamember is
            // a valid value, and thus we need the datasource to also be IList
            // Then we need a parameterized IEnumerable, which returns null.
            // *Observation: if it is empty and it doesn't implement IList,
            // it doesn't have a way to get the properties, and will throw an exc
            StringCollection str_coll = new StringCollection();

            obj = ListBindingHelper.GetList(str_coll, "Length");
            Assert.IsNull(obj, "#H1");

            // IEnumerable that returns instances of ICustomTypeDescriptor
            // Use DataTable as source, which returns, when enumerating,
            // instances of DataRowView, which in turn implement ICustomTypeDescriptor
            DataTable table = new DataTable();

            table.Columns.Add("Id", typeof(int));
            table.Rows.Add(666);
            object l = ListBindingHelper.GetList(table, "Id");

            Assert.AreEqual(666, l, "#J1");

            try
            {
                ListBindingHelper.GetList(list_container, "DontExist");
                Assert.Fail("#EXC1");
            }
            catch (ArgumentException)
            {
            }

            // Empty IEnumerable not implementing IList
            // Don't have a way to know whether at least datamember is valid or not.
            try
            {
                stack.Clear();
                obj = ListBindingHelper.GetList(stack, "Value");
                Assert.Fail("#EXC3");
            }
            catch (ArgumentException)
            {
            }
        }