Exemple #1
0
        public int Compare(TreeNode x, TreeNode y, SortColumnDescription sortDescription)
        {
            int         c  = 0;
            IComparable xc = null;
            IComparable yc = null;

#if WPF
            PropertyDescriptorCollection descriptor1 = TypeDescriptor.GetProperties(x.Item.GetType());
#else
            PropertyInfoCollection descriptor1 = new PropertyInfoCollection(x.Item.GetType());
#endif
            xc = descriptor1.GetValue(x.Item, sortDescription.ColumnName) as IComparable;

#if WPF
            PropertyDescriptorCollection descriptor2 = TypeDescriptor.GetProperties(y.Item.GetType());
#else
            PropertyInfoCollection descriptor2 = new PropertyInfoCollection(y.Item.GetType());
#endif
            yc = descriptor1.GetValue(y.Item, sortDescription.ColumnName) as IComparable;

            if (xc != null)
            {
                c = xc.CompareTo(yc);
            }
            else if (yc != null)
            {
                c = -1;
            }

            if (sortDescription.SortDirection == ListSortDirection.Descending)
            {
                c = -c;
            }
            return(c);
        }
Exemple #2
0
        internal void GetGroupResult(object ItemData)
        {
            var    descriptor = ListView.DataSource.GroupDescriptors[0];
            object key;

            if (descriptor.KeySelector == null)
            {
                var propertyInfoCollection = new PropertyInfoCollection(ItemData.GetType());
                key = propertyInfoCollection.GetValue(ItemData, descriptor.PropertyName);
            }
            else
            {
                key = descriptor.KeySelector(ItemData);
            }

            for (int i = 0; i < this.ListView.DataSource.Groups.Count; i++)
            {
                var group = this.ListView.DataSource.Groups[i];
                if ((group.Key != null && group.Key.Equals(key)) || group.Key == key)
                {
                    itemGroup = group;
                    break;
                }
                group = null;
            }
            descriptor = null;
            key        = null;
        }
Exemple #3
0
        private void ListView_SelectionChanging(object sender, ItemSelectionChangingEventArgs e)
        {
            GroupResult actualGroup   = null;
            object      key           = null;
            var         selectedItems = listView.SelectedItems;

            //To Cancel the Deselection
            if (e.RemovedItems.Count > 0 && selectedItems.Contains(e.RemovedItems[0]))
            {
                e.Cancel = true;
                return;
            }

            //To return when SelectedItems is zero
            if (e.AddedItems.Count <= 0)
            {
                return;
            }

            var itemData = (e.AddedItems[0] as Contacts);

            var descriptor = listView.DataSource.GroupDescriptors[0];

            if (descriptor.KeySelector == null)
            {
                var pbCollection = new PropertyInfoCollection(itemData.GetType());
                key = pbCollection.GetValue(itemData, descriptor.PropertyName);
            }
            else
            {
                key = descriptor.KeySelector(itemData);
            }

            for (int i = 0; i < listView.DataSource.Groups.Count; i++)
            {
                var group = listView.DataSource.Groups[i];

                if ((group.Key != null && group.Key.Equals(key)) || group.Key == key)
                {
                    actualGroup = group;
                    break;
                }
            }

            if (selectedItems.Count > 0)
            {
                foreach (var item in actualGroup.Items)
                {
                    var groupItem = item;

                    if (selectedItems.Contains(groupItem))
                    {
                        listView.SelectedItems.Remove(groupItem);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Gets the value for the specific property.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="property">the property whose value needs to return.</param>
        /// <returns>value.</returns>
        internal static object GetValue(object data, string propertyName)
        {
            if (DynamicHelper.CheckIsDynamicObject(data.GetType()))
            {
                return(new DynamicHelper().GetValue(data, propertyName));
                //return DynamicPropertiesProvider.GetDynamicValue(data, propertyName);
            }
            else
            {
#if WPF
                PropertyDescriptorCollection descriptor = TypeDescriptor.GetProperties(data.GetType());
#else
                PropertyInfoCollection descriptor = new PropertyInfoCollection(data.GetType());
#endif
                return(descriptor.GetValue(data, propertyName));
            }
        }