SortedBindingList

SortedBindingList

Old forum URL: forums.lhotka.net/forums/t/420.aspx


Ouistiti posted on Tuesday, June 20, 2006

Hello,

I'm probably missing something, but I wonder why the implementation of the IndexOf method of class SortedBindingList (Csla 2.0.1) returns the index of the original item, not the sorted one.

Thanks for your answer.

RockfordLhotka replied on Tuesday, June 20, 2006

I think this is a bug, thanks for catching it. I'll fix it in cvs so it will be fixed in subsequent releases (2.0.3 and higher).

burmajam replied on Wednesday, June 21, 2006

Is it bug in line 647 on SortedBindingList? When grid is not sorted everything is fine, but when I sort it, exception raises here (red line)?

    /// <summary>
    /// Gets the child item at the specified index in the list,
    /// honoring the sort order of the items.
    /// </summary>
    /// <param name="index">The index of the item in the sorted list.</param>
    public T this[int index]
    {
      get
      {
        if (_sorted)
          return _list[OriginalIndex(index)];
        else
          return _list[index];
      }
      set
      {
        if (_sorted)
          _list[OriginalIndex(index)] = value;
        else
          _list[index] = value;
      }
    }

RockfordLhotka replied on Wednesday, June 21, 2006

burmajam, can you provide more details? I use SortedBindingList on a regular basis and don't get an exception there. What is the specific scenario where you see this exception?

burmajam replied on Wednesday, June 21, 2006

OK here's what I've done. Sorry for the language I hope it won't cofuse you.

    [Serializable()]
    public class RobaSpisak : ReadOnlyListBase<RobaSpisak, RobaInfo>
    {
        // all cached stuff ....
        private Collection<RobaInfo> _svaRoba = new Collection<RobaInfo>();
        public Collection<RobaInfo> SvaRoba
        {
            get { return _svaRoba; }
        }

        public void FilterRoba(string naziv)
        {
            this.Items.Clear();
            foreach (RobaInfo roba in SvaRoba)
            {
                if (roba.Naziv.ToUpper().IndexOf(naziv.ToUpper()) != -1)
                    this.Items.Add(roba);
            }
        }

        // maybe this is the problem. I use this Property as datasource for ObjectDataSource in UI
        private Csla.SortedBindingList<RobaInfo> _asDataSource;
        public Csla.SortedBindingList<RobaInfo> AsDataSource
        {
            get { return _asDataSource; }
        }

        /// <summary>
        /// Postavlja AsDataSource atribut
        /// </summary>
        internal void SetAsDataSource()
        {
            _asDataSource = new Csla.SortedBindingList<RobaInfo>(this);
        }

        #region Factory Methods

        /// <summary>
        /// Vraća spisak sve robe. i postavalja AsDataSource
        /// </summary>
        public static RobaSpisak GetRobaSpisak()
        {
            RobaSpisak rezultat = DataPortal.Fetch<RobaSpisak>(new Criteria());
            rezultat.SetAsDataSource();
            return rezultat;
        }


        private RobaSpisak()
        { /* require use of factory methods */ }

        #endregion

        #region Data Access

        [Serializable()]
        private class Criteria
        { /* no criteria - retrieve them all */ }

        private void DataPortal_Fetch(Criteria criteria)
        {
            // fetch bez filtera
            Fetch();
        }

        private void Fetch()
        {
             // this part is not interesting becouse it handles MySQL data
             //-....
                            RobaInfo info = new RobaInfo(
                              dr.GetGuid(0),
                              lastChanged_AT,
                              dr.GetString(2),
                              dr.GetString(3),
                              dr.GetString(4),
                              dr.GetDouble(5),
                              dr.GetString(6),
                              dr.GetString(7)
                              );
                            this.Add(info);
                            _svaRoba.Add(info);
                        }
                        IsReadOnly = true;
                    }
                }
            }
        }
        #endregion
   }

I guess I did some silly things, but I wanted cached-sortable-filterable list. Embarrassed [:$] It does work, but not when grid is sorted

Thank you

Bu®majaM

Ouistiti replied on Wednesday, June 21, 2006

Thanks for your quick answer.


De : RockfordLhotka [mailto:cslanet@lhotka.net]
Envoyé : mercredi 21 juin 2006 16:09
À : dh_ouistiti@hotmail.com
Objet : Re: [CSLA .NET] SortedBindingList

I think this is a bug, thanks for catching it. I'll fix it in cvs so it will be fixed in subsequent releases (2.0.3 and higher).


Copyright (c) Marimer LLC