Таблица атрибутивных данных

0 голосов
спросил 24 Ноя, 09 от Commrad1 (3,660 баллов) в категории Программные продукты Esri
День добрый! В NET есть пример отображения аттрибутивных таблиц в
DataGrid View через назначение источника bindingSource. Как
организовать сортировку и фильтры в данном подходе. Заранее благодарен!

3 Ответы

0 голосов
ответил 24 Ноя, 09 от gorxgor (340 баллов)
Если речь идет о TableWrapper, то для сортировки нужно добавить:

        #region *** СОРТИРОВКА ***

        /// <summary>
        /// Gets a value indicating whether the list supports searching.
        /// </summary>
        /// <returns>
        /// true if the list supports searching; otherwise, false. The default is false.
        /// </returns>
        protected override bool SupportsSearchingCore
        {
            get { return true; }
        }

        /// <summary>
        /// Gets a value indicating whether the list supports sorting.
        /// </summary>
        /// <returns>
        /// true if the list supports sorting; otherwise, false. The default is false.
        /// </returns>
        protected override bool SupportsSortingCore
        {
            get { return true; }
        }

        /// <summary>
        /// Признак того, что есть сортировка
        /// </summary>
        private bool isSortedCore = false;

        /// <summary>
        /// Gets a value indicating whether the list is sorted.
        /// </summary>
        /// <returns>
        /// true if the list is sorted; otherwise, false. The default is false.
        /// </returns>
        protected override bool IsSortedCore
        {
            get { return isSortedCore; }
        }


        /// <summary>
        /// Направление сортировки
        /// </summary>
        private ListSortDirection sortDirectionCore = ListSortDirection.Ascending;

        /// <summary>
        /// Gets the direction the list is sorted.
        /// </summary>
        /// <returns>
        /// One of the <see cref="T:System.ComponentModel.ListSortDirection" /> values. The default is <see cref="F:System.ComponentModel.ListSortDirection.Ascending" />.
        /// </returns>
        protected override ListSortDirection SortDirectionCore
        {
            get { return sortDirectionCore; }
        }

        /// <summary>
        /// Свойство для сортировки
        /// </summary>
        private PropertyDescriptor sortPropertyCore = null;

        /// <summary>
        /// Gets the property descriptor that is used for sorting the list if sorting is implemented in a derived class; otherwise, returns null.
        /// </summary>
        /// <returns>
        /// The <see cref="T:System.ComponentModel.PropertyDescriptor" /> used for sorting the list.
        /// </returns>
        protected override PropertyDescriptor SortPropertyCore
        {
            get { return sortPropertyCore; }
        }


        /// <summary>
        /// Sorts the items if overridden in a derived class; otherwise, throws a <see cref="T:System.NotSupportedException" />.
        /// </summary>
        /// <param name="prop">A <see cref="T:System.ComponentModel.PropertyDescriptor" /> that specifies the property to sort on.</param>
        /// <param name="direction">One of the <see cref="T:System.ComponentModel.ListSortDirection" />  values.</param>
        /// <exception cref="T:System.NotSupportedException">Method is not overridden in a derived class. </exception>
        protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
        {
            sortDirectionCore = direction;
            sortPropertyCore = prop;

            GenericSortComparer<IRow> comparer = new GenericSortComparer<IRow>(prop, direction);

            List<IRow> listRef = this.Items as List<IRow>;
            if (listRef != null)
            {
                listRef.Sort(comparer);

                isSortedCore = true;

                OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
            }
        }

        #endregion

0 голосов
ответил 25 Ноя, 09 от Commrad1 (3,660 баллов)
Если речь идет о TableWrapper, то для сортировки нужно добавить:

        #region *** СОРТИРОВКА ***

        /// <summary>
        /// Gets a value indicating whether the list supports searching.
        /// </summary>
        /// <returns>
        /// true if the list supports searching; otherwise, false. The default is false.
        /// </returns>
        protected override bool SupportsSearchingCore
        {
            get { return true; }
        }

        /// <summary>
        /// Gets a value indicating whether the list supports sorting.
        /// </summary>
        /// <returns>
        /// true if the list supports sorting; otherwise, false. The default is false.
        /// </returns>
        protected override bool SupportsSortingCore
        {
            get { return true; }
        }

        /// <summary>
        /// Признак того, что есть сортировка
        /// </summary>
        private bool isSortedCore = false;

        /// <summary>
        /// Gets a value indicating whether the list is sorted.
        /// </summary>
        /// <returns>
        /// true if the list is sorted; otherwise, false. The default is false.
        /// </returns>
        protected override bool IsSortedCore
        {
            get { return isSortedCore; }
        }


        /// <summary>
        /// Направление сортировки
        /// </summary>
        private ListSortDirection sortDirectionCore = ListSortDirection.Ascending;

        /// <summary>
        /// Gets the direction the list is sorted.
        /// </summary>
        /// <returns>
        /// One of the <see cref="T:System.ComponentModel.ListSortDirection" /> values. The default is <see cref="F:System.ComponentModel.ListSortDirection.Ascending" />.
        /// </returns>
        protected override ListSortDirection SortDirectionCore
        {
            get { return sortDirectionCore; }
        }

        /// <summary>
        /// Свойство для сортировки
        /// </summary>
        private PropertyDescriptor sortPropertyCore = null;

        /// <summary>
        /// Gets the property descriptor that is used for sorting the list if sorting is implemented in a derived class; otherwise, returns null.
        /// </summary>
        /// <returns>
        /// The <see cref="T:System.ComponentModel.PropertyDescriptor" /> used for sorting the list.
        /// </returns>
        protected override PropertyDescriptor SortPropertyCore
        {
            get { return sortPropertyCore; }
        }


        /// <summary>
        /// Sorts the items if overridden in a derived class; otherwise, throws a <see cref="T:System.NotSupportedException" />.
        /// </summary>
        /// <param name="prop">A <see cref="T:System.ComponentModel.PropertyDescriptor" /> that specifies the property to sort on.</param>
        /// <param name="direction">One of the <see cref="T:System.ComponentModel.ListSortDirection" />  values.</param>
        /// <exception cref="T:System.NotSupportedException">Method is not overridden in a derived class. </exception>
        protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
        {
            sortDirectionCore = direction;
            sortPropertyCore = prop;

            GenericSortComparer<IRow> comparer = new GenericSortComparer<IRow>(prop, direction);

            List<IRow> listRef = this.Items as List<IRow>;
            if (listRef != null)
            {
                listRef.Sort(comparer);

                isSortedCore = true;

                OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
            }
        }

        #endregion

       Спасибо большое. Пишу на VB.NET немогу разобраться с этой строкой
GenericSortComparer<IRow> comparer = new GenericSortComparer<IRow>(prop, direction);
protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
        {
            sortDirectionCore = di
0 голосов
ответил 26 Ноя, 09 от gorxgor (340 баллов)
Извиняюсь, выдирал из проекта и не заметил ссылку на наш класс:

    /// <summary>
    /// Gemeric реализация IComparer для сортировки списка объектов по любому полю
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class GenericSortComparer<T> : IComparer<T>
    {
        /// <summary>
        /// PropertyDescriptor свойства по которому сортируем
        /// </summary>
        private PropertyDescriptor propertyDescriptor = null;

        /// <summary>
        /// Направление сортировки
        /// </summary>
        private ListSortDirection sortDirection = ListSortDirection.Ascending;

        /// <summary>
        /// Конструктор
        /// </summary>
        /// <param name="propertyDescriptor">Свойство</param>
        /// <param name="direction">Напрваление</param>
        public GenericSortComparer(PropertyDescriptor propertyDescriptor, ListSortDirection direction)
        {
            this.propertyDescriptor = propertyDescriptor;
            sortDirection = direction;
        }

        #region Implementation of IComparer<T>

        /// <summary>
        /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        /// </summary>
        /// <returns>
        /// Value Condition Less than zero<paramref name="x" /> is less than <paramref name="y" />.Zero<paramref name="x" /> equals <paramref name="y" />.Greater than zero<paramref name="x" /> is greater than <paramref name="y" />.
        /// </returns>
        /// <param name="x">The first object to compare.</param>
        /// <param name="y">The second object to compare.</param>
        public int Compare(T x, T y)
        {
            object xValue = propertyDescriptor.GetValue(x);
            object yValue = propertyDescriptor.GetValue(y);

            int retValue = 0;

            // если кто-то из объектов IComparable
            if (xValue is IComparable)
            {
                retValue = ((IComparable)xValue).CompareTo(yValue);
            }
            else if (yValue is IComparable)
            {
                retValue = ((IComparable)yValue).CompareTo(xValue);
            }
            // иначе сравниваем как строки
            else if (!xValue.Equals(yValue))
            {
                retValue = xValue.ToString().CompareTo(yValue.ToString());
            }

            if (sortDirection == ListSortDirection.Ascending)
            {
                return retValue;
            }
            return retValue * -1;

        }

        #endregion


    }

Добро пожаловать на сайт Вопросов и Ответов, где вы можете задавать вопросы по GIS тематике и получать ответы от других членов сообщества.
...