Пример #1
0
        private bool BindingMemberInfoInDataManager(BindingMemberInfo bindingMemberInfo)
        {
            if (dataManager == null)
            {
                return(false);
            }
            PropertyDescriptorCollection props = dataManager.GetItemProperties();
            int propsCount = props.Count;

            for (int i = 0; i < propsCount; i++)
            {
                if (typeof(IList).IsAssignableFrom(props[i].PropertyType))
                {
                    continue;
                }
                if (props[i].Name.Equals(bindingMemberInfo.BindingField))
                {
                    return(true);
                }
            }

            for (int i = 0; i < propsCount; i++)
            {
                if (typeof(IList).IsAssignableFrom(props[i].PropertyType))
                {
                    continue;
                }
                if (String.Compare(props[i].Name, bindingMemberInfo.BindingField, true, CultureInfo.CurrentCulture) == 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        protected object FilterItemOnProperty(object item, string field)
        {
            if (item == null)
            {
                return(null);
            }

            if (field == null || field == string.Empty)
            {
                return(item);
            }

            PropertyDescriptor prop = null;

            if (data_manager != null)
            {
                PropertyDescriptorCollection col = data_manager.GetItemProperties();
                prop = col.Find(field, true);
            }
            else
            {
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(item);
                prop = properties.Find(field, true);
            }

            if (prop == null)
            {
                return(item);
            }

            return(prop.GetValue(item));
        }
Пример #3
0
        // Create column styles for this TableStyle
        internal void CreateColumnsForTable(bool onlyBind)
        {
            CurrencyManager     mgr = manager;
            DataGridColumnStyle st;

            if (mgr == null)
            {
                mgr = datagrid.ListManager;

                if (mgr == null)
                {
                    return;
                }
            }

            for (int i = 0; i < column_styles.Count; i++)
            {
                column_styles[i].bound = false;
            }

            table_relations.Clear();
            PropertyDescriptorCollection propcol = mgr.GetItemProperties();

            for (int i = 0; i < propcol.Count; i++)
            {
                // The column style is already provided by the user
                st = column_styles[propcol[i].Name];
                if (st != null)
                {
                    if (st.Width == -1)
                    {
                        st.Width = CurrentPreferredColumnWidth;
                    }

                    st.PropertyDescriptor = propcol[i];
                    st.bound = true;
                    continue;
                }

                if (onlyBind == true)
                {
                    continue;
                }

                if (typeof(IBindingList).IsAssignableFrom(propcol[i].PropertyType))
                {
                    table_relations.Add(propcol[i].Name);
                }
                else
                {
                    st             = CreateGridColumn(propcol[i], true);
                    st.bound       = true;
                    st.grid        = datagrid;
                    st.MappingName = propcol[i].Name;
                    st.HeaderText  = propcol[i].Name;
                    st.Width       = CurrentPreferredColumnWidth;
                    column_styles.Add(st);
                }
            }
        }
Пример #4
0
        private bool BindingMemberInfoInDataManager(BindingMemberInfo bindingMemberInfo)
        {
            if (dataManager == null)
            {
                return(false);
            }
            PropertyDescriptorCollection props = dataManager.GetItemProperties();
            int  propsCount = props.Count;
            bool fieldFound = false;

            for (int i = 0; i < propsCount; i++)
            {
                if (typeof(IList).IsAssignableFrom(props[i].PropertyType))
                {
                    continue;
                }
                if (props[i].Name.Equals(bindingMemberInfo.BindingField))
                {
                    fieldFound = true;
                    break;
                }
            }

            return(fieldFound);
        }
Пример #5
0
 /// <summary>
 /// 获取数据项索引
 /// </summary>
 /// <param name="dataManager">数据管理对象</param>
 /// <param name="propertyName">属性名称</param>
 /// <param name="propertyValue">属性值</param>
 /// <returns>返回指定属性名称的项的索引</returns>
 public static int GetIndex(CurrencyManager dataManager, string propertyName, object propertyValue)
 {
     if (propertyValue == null) return -1;
     PropertyDescriptorCollection props = dataManager.GetItemProperties();
     PropertyDescriptor property = props.Find(propertyName, true);
     if (property == null) throw new ArgumentNullException(propertyName);
     var list = dataManager.List;
     if ((list is IBindingList) && ((IBindingList)list).SupportsSearching)
     {
         return ((IBindingList)list).Find(property, propertyValue);
     }
     for (int i = 0; i < list.Count; i++)
     {
         object obj2 = property.GetValue(list[i]);
         if (propertyValue.ToStringOrEmpty().Equals(obj2.ToStringOrEmpty()))
         {
             return i;
         }
     }
     return -1;
 }
Пример #6
0
 protected virtual void SetDataGridInColumn(DataGrid value)
 {
     if ((this.PropertyDescriptor == null) && (value != null))
     {
         CurrencyManager listManager = value.ListManager;
         if (listManager != null)
         {
             PropertyDescriptorCollection itemProperties = listManager.GetItemProperties();
             int count = itemProperties.Count;
             for (int i = 0; i < itemProperties.Count; i++)
             {
                 System.ComponentModel.PropertyDescriptor descriptor = itemProperties[i];
                 if (!typeof(IList).IsAssignableFrom(descriptor.PropertyType) && descriptor.Name.Equals(this.HeaderText))
                 {
                     this.PropertyDescriptor = descriptor;
                     return;
                 }
             }
         }
     }
 }
Пример #7
0
        protected void CheckValidDataSource(CurrencyManager value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("CurrencyManager cannot be null");
            }

            if (property_descriptor == null)
            {
                property_descriptor = value.GetItemProperties()[mapping_name];

//              Console.WriteLine ("mapping name = {0}", mapping_name);
//              foreach (PropertyDescriptor prop in value.GetItemProperties ()) {
//                  Console.WriteLine (" + prop = {0}", prop.Name);
//              }

                if (property_descriptor == null)
                {
                    throw new InvalidOperationException("The PropertyDescriptor for this column is a null reference");
                }

                /*MonoTests.System.Windows.Forms.DataGridColumnStyleTest.GetColumnValueAtRow : System.InvalidOperationException : The 'foo' DataGridColumnStyle cannot be used because it is not associated with a Property or Column in the DataSource.*/
            }
        }
Пример #8
0
 /// <summary>
 /// 获取数据项的属性值
 /// </summary>
 /// <param name="dataManager">数据管理对象</param>
 /// <param name="item">数据项</param>
 /// <param name="propertyName">属性名称</param>
 /// <returns>返回指定属性的值</returns>
 public static object GetValue(CurrencyManager dataManager, object item, string propertyName)
 {
     if (item == null || propertyName == null || propertyName.Length == 0) return null;
     try
     {
         PropertyDescriptor descriptor = dataManager != null ?
             dataManager.GetItemProperties().Find(propertyName, true) :
             TypeDescriptor.GetProperties(item).Find(propertyName, true);
         if (descriptor != null)
         {
             item = descriptor.GetValue(item);
         }
     }
     catch
     {
         return null;
     }
     return item;
 }
		protected void CheckValidDataSource (CurrencyManager value)
		{
			if (value == null) {
				throw new ArgumentNullException ("CurrencyManager cannot be null");
			}
			
			if (property_descriptor == null) {
				property_descriptor = value.GetItemProperties ()[mapping_name];

// 				Console.WriteLine ("mapping name = {0}", mapping_name);
// 				foreach (PropertyDescriptor prop in value.GetItemProperties ()) {
// 					Console.WriteLine (" + prop = {0}", prop.Name);
// 				}

				if (property_descriptor == null)
					throw new InvalidOperationException ("The PropertyDescriptor for this column is a null reference");

				 /*MonoTests.System.Windows.Forms.DataGridColumnStyleTest.GetColumnValueAtRow : System.InvalidOperationException : The 'foo' DataGridColumnStyle cannot be used because it is not associated with a Property or Column in the DataSource.*/

				
			}
		}
Пример #10
0
        internal void SetGridColumnStylesCollection(CurrencyManager listManager) {
            // when we are setting the gridColumnStyles, do not handle any gridColumnCollectionChanged events
            gridColumns.CollectionChanged -= new CollectionChangeEventHandler(this.OnColumnCollectionChanged);

            PropertyDescriptorCollection propCollection = listManager.GetItemProperties();

            // we need to clear the relations list
            if (relationsList.Count > 0)
                relationsList.Clear();

            Debug.Assert(propCollection != null, "propCollection is null: how that happened?");
            int propCount = propCollection.Count;
            for (int i = 0; i < propCount; i++) {
                PropertyDescriptor prop = propCollection[i];
                Debug.Assert(prop != null, "prop is null: how that happened?");
                // do not take into account the properties that are browsable.
                if (!prop.IsBrowsable)
                    continue;
                if (PropertyDescriptorIsARelation(prop)) {
                    // relation
                    relationsList.Add(prop.Name);
                }
                else
                {
                    // column
                    DataGridColumnStyle col = this.CreateGridColumn(prop, this.isDefaultTableStyle);
                    if (this.isDefaultTableStyle)
                        gridColumns.AddDefaultColumn(col);
                    else {
                        col.MappingName = prop.Name;
                        col.HeaderText = prop.Name;
                        gridColumns.Add(col);
                    }
                }
            }

            // now we are able to handle the collectionChangeEvents
            gridColumns.CollectionChanged += new CollectionChangeEventHandler(this.OnColumnCollectionChanged);
        }
Пример #11
0
 internal void SetRelationsList(CurrencyManager listManager) {
     PropertyDescriptorCollection propCollection = listManager.GetItemProperties();
     Debug.Assert(!this.IsDefault, "the grid can set the relations only on a table that was manually added by the user");
     int propCount = propCollection.Count;
     if (relationsList.Count > 0)
         relationsList.Clear();
     for (int i = 0; i < propCount; i++) {
         PropertyDescriptor prop = propCollection[i];
         Debug.Assert(prop != null, "prop is null: how that happened?");
         if (PropertyDescriptorIsARelation(prop)) {
             // relation
             relationsList.Add(prop.Name);
         }
     }
 }
 internal void SetRelationsList(CurrencyManager listManager)
 {
     PropertyDescriptorCollection itemProperties = listManager.GetItemProperties();
     int count = itemProperties.Count;
     if (this.relationsList.Count > 0)
     {
         this.relationsList.Clear();
     }
     for (int i = 0; i < count; i++)
     {
         PropertyDescriptor prop = itemProperties[i];
         if (PropertyDescriptorIsARelation(prop))
         {
             this.relationsList.Add(prop.Name);
         }
     }
 }
 internal void SetGridColumnStylesCollection(CurrencyManager listManager)
 {
     this.gridColumns.CollectionChanged -= new CollectionChangeEventHandler(this.OnColumnCollectionChanged);
     PropertyDescriptorCollection itemProperties = listManager.GetItemProperties();
     if (this.relationsList.Count > 0)
     {
         this.relationsList.Clear();
     }
     int count = itemProperties.Count;
     for (int i = 0; i < count; i++)
     {
         PropertyDescriptor prop = itemProperties[i];
         if (prop.IsBrowsable)
         {
             if (PropertyDescriptorIsARelation(prop))
             {
                 this.relationsList.Add(prop.Name);
             }
             else
             {
                 DataGridColumnStyle column = this.CreateGridColumn(prop, this.isDefaultTableStyle);
                 if (this.isDefaultTableStyle)
                 {
                     this.gridColumns.AddDefaultColumn(column);
                 }
                 else
                 {
                     column.MappingName = prop.Name;
                     column.HeaderText = prop.Name;
                     this.gridColumns.Add(column);
                 }
             }
         }
     }
     this.gridColumns.CollectionChanged += new CollectionChangeEventHandler(this.OnColumnCollectionChanged);
 }
 private void PairTableStylesAndGridColumns(CurrencyManager lm, DataGridTableStyle gridTable, bool forceColumnCreation)
 {
     PropertyDescriptorCollection itemProperties = lm.GetItemProperties();
     GridColumnStylesCollection gridColumnStyles = gridTable.GridColumnStyles;
     if (!gridTable.IsDefault && (string.Compare(lm.GetListName(), gridTable.MappingName, true, CultureInfo.InvariantCulture) == 0))
     {
         if ((gridTable.GridColumnStyles.Count == 0) && !base.DesignMode)
         {
             if (forceColumnCreation)
             {
                 gridTable.SetGridColumnStylesCollection(lm);
             }
             else
             {
                 gridTable.SetRelationsList(lm);
             }
         }
         else
         {
             for (int i = 0; i < gridColumnStyles.Count; i++)
             {
                 gridColumnStyles[i].PropertyDescriptor = null;
             }
             for (int j = 0; j < itemProperties.Count; j++)
             {
                 DataGridColumnStyle style = gridColumnStyles.MapColumnStyleToPropertyName(itemProperties[j].Name);
                 if (style != null)
                 {
                     style.PropertyDescriptor = itemProperties[j];
                 }
             }
             gridTable.SetRelationsList(lm);
         }
     }
     else
     {
         gridTable.SetGridColumnStylesCollection(lm);
         if ((gridTable.GridColumnStyles.Count > 0) && (gridTable.GridColumnStyles[0].Width == -1))
         {
             this.InitializeColumnWidths();
         }
     }
 }