예제 #1
0
        /// <summary>
        /// Return the ListViewItem that appears immediately before the given item.
        /// If the given item is null, the last item in the list will be returned.
        /// Return null if the given item is the first item.
        /// </summary>
        /// <param name="itemToFind">The item that is before the item that is returned</param>
        /// <returns>A ListViewItem</returns>
        public override OLVListItem GetPreviousItem(OLVListItem itemToFind)
        {
            if (!this.ShowGroups)
            {
                return(base.GetPreviousItem(itemToFind));
            }

            // Sanity
            if (this.OLVGroups == null || this.OLVGroups.Count == 0)
            {
                return(null);
            }

            // If the given items is null, return the last member of the last group
            if (itemToFind == null)
            {
                OLVGroup lastGroup = this.OLVGroups[this.OLVGroups.Count - 1];
                return(this.GetItem(this.GroupingStrategy.GetGroupMember(lastGroup, lastGroup.VirtualItemCount - 1)));
            }

            // Find where this item occurs (which group and where in that group)
            int groupIndex       = this.GroupingStrategy.GetGroup(itemToFind.Index);
            int indexWithinGroup = this.GroupingStrategy.GetIndexWithinGroup(this.OLVGroups[groupIndex], itemToFind.Index);

            // If it's not the first member of the group, just return the previous member
            if (indexWithinGroup > 0)
            {
                return(this.GetItem(this.GroupingStrategy.GetGroupMember(this.OLVGroups[groupIndex], indexWithinGroup - 1)));
            }

            // The item is the first member of its group. Return the last member of the previous group
            // (if there is one)
            if (groupIndex > 0)
            {
                OLVGroup previousGroup = this.OLVGroups[groupIndex - 1];
                return(this.GetItem(this.GroupingStrategy.GetGroupMember(previousGroup, previousGroup.VirtualItemCount - 1)));
            }

            return(null);
        }
        /// <summary>
        /// Create an OLVGroup for the given information
        /// </summary>
        /// <param name="key"></param>
        /// <param name="count"></param>
        /// <param name="hasCollapsibleGroups"></param>
        /// <returns></returns>
        public OLVGroup CreateGroup(object key, int count, bool hasCollapsibleGroups)
        {
            string title = GroupByColumn.ConvertGroupKeyToTitle(key);

            if (!String.IsNullOrEmpty(TitleFormat))
            {
                string format = (count == 1 ? TitleSingularFormat : TitleFormat);
                try
                {
                    title = String.Format(format, title, count);
                }
                catch (FormatException)
                {
                    title = "Invalid group format: " + format;
                }
            }
            OLVGroup lvg = new OLVGroup(title);

            lvg.Column      = GroupByColumn;
            lvg.Collapsible = hasCollapsibleGroups;
            lvg.Key         = key;
            lvg.SortValue   = key as IComparable;
            return(lvg);
        }
예제 #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="group"></param>
 /// <param name="itemIndex"></param>
 /// <returns></returns>
 public override int GetIndexWithinGroup(OLVGroup group, int itemIndex) {
     return group.Contents.IndexOf(itemIndex);
 }
예제 #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="group"></param>
 /// <param name="indexWithinGroup"></param>
 /// <returns></returns>
 public override int GetGroupMember(OLVGroup group, int indexWithinGroup) {
     return (int)group.Contents[indexWithinGroup];
 }
예제 #5
0
        /// <summary>
        /// Create groups for FastListView
        /// </summary>
        /// <param name="parmameters"></param>
        /// <returns></returns>
        public override IList<OLVGroup> GetGroups(GroupingParameters parmameters) {

            // There is a lot of overlap between this method and ObjectListView.MakeGroups()
            // Any changes made here may need to be reflected there

            // This strategy can only be used on FastObjectListViews
            FastObjectListView folv = (FastObjectListView)parmameters.ListView;

            // Separate the list view items into groups, using the group key as the descrimanent
            int objectCount = 0;
            NullableDictionary<object, List<object>> map = new NullableDictionary<object, List<object>>();
            foreach (object model in folv.FilteredObjects) {
                object key = parmameters.GroupByColumn.GetGroupKey(model);
                if (!map.ContainsKey(key))
                    map[key] = new List<object>();
                map[key].Add(model);
                objectCount++;
            }

            // Sort the items within each group
            // TODO: Give parameters a ModelComparer property
            OLVColumn primarySortColumn = parmameters.SortItemsByPrimaryColumn ? parmameters.ListView.GetColumn(0) : parmameters.PrimarySort;
            ModelObjectComparer sorter = new ModelObjectComparer(primarySortColumn, parmameters.PrimarySortOrder,
                parmameters.SecondarySort, parmameters.SecondarySortOrder);
            foreach (object key in map.Keys) {
                map[key].Sort(sorter);
            }

            // Make a list of the required groups
            List<OLVGroup> groups = new List<OLVGroup>();
            foreach (object key in map.Keys) {
                string title = parmameters.GroupByColumn.ConvertGroupKeyToTitle(key);
                if (!String.IsNullOrEmpty(parmameters.TitleFormat)) {
                    int count = map[key].Count;
                    string format = (count == 1 ? parmameters.TitleSingularFormat : parmameters.TitleFormat);
                    try {
                        title = String.Format(format, title, count);
                    } catch (FormatException) {
                        title = "Invalid group format: " + format;
                    }
                }
                OLVGroup lvg = new OLVGroup(title);
                lvg.Collapsible = folv.HasCollapsibleGroups;
                lvg.Key = key;
                lvg.SortValue = key as IComparable;
                lvg.Contents = map[key].ConvertAll<int>(delegate(object x) { return folv.IndexOf(x); });
                lvg.VirtualItemCount = map[key].Count;
                if (parmameters.GroupByColumn.GroupFormatter != null)
                    parmameters.GroupByColumn.GroupFormatter(lvg, parmameters);
                groups.Add(lvg);
            }

            // Sort the groups
            if (parmameters.GroupByOrder != SortOrder.None)
                groups.Sort(parmameters.GroupComparer ?? new OLVGroupComparer(parmameters.GroupByOrder));

            // Build an array that remembers which group each item belongs to.
            this.indexToGroupMap = new List<int>(objectCount);
            this.indexToGroupMap.AddRange(new int[objectCount]);

            for (int i = 0; i < groups.Count; i++) {
                OLVGroup group = groups[i];
                List<int> members = (List<int>)group.Contents;
                foreach (int j in members)
                    this.indexToGroupMap[j] = i;
            }

            return groups;
        }
예제 #6
0
 /// <summary>
 /// Return the index at which the given item is shown in the given group
 /// </summary>
 /// <param name="group"></param>
 /// <param name="itemIndex"></param>
 /// <returns></returns>
 public virtual int GetIndexWithinGroup(OLVGroup group, int itemIndex) {
     return -1;
 }
예제 #7
0
 /// <summary>
 /// Create a GroupStateChangedEventArgs
 /// </summary>
 /// <param name="group"></param>
 /// <param name="oldState"> </param>
 /// <param name="newState"> </param>
 public GroupStateChangedEventArgs(OLVGroup group, GroupState oldState, GroupState newState) {
     this.group = group;
     this.oldState = oldState;
     this.newState = newState;
 }
예제 #8
0
 /// <summary>
 /// Create a GroupTaskClickedEventArgs
 /// </summary>
 /// <param name="group"></param>
 public GroupTaskClickedEventArgs(OLVGroup group)
 {
     this.group = group;
 }
 public override int GetGroupMember(OLVGroup group, int indexWithinGroup)
 {
     return((int)group.Contents[indexWithinGroup]);
 }
예제 #10
0
        /// <summary>
        /// Create groups for FastListView
        /// </summary>
        /// <param name="parmameters"></param>
        /// <returns></returns>
        public override IList <OLVGroup> GetGroups(GroupingParameters parmameters)
        {
            // There is a lot of overlap between this method and ObjectListView.MakeGroups()
            // Any changes made here may need to be reflected there

            // This strategy can only be used on FastObjectListViews
            FastObjectListView folv = (FastObjectListView)parmameters.ListView;

            // Separate the list view items into groups, using the group key as the descrimanent
            int objectCount = 0;
            NullableDictionary <object, List <object> > map = new NullableDictionary <object, List <object> >();

            foreach (object model in folv.FilteredObjects)
            {
                object key = parmameters.GroupByColumn.GetGroupKey(model);
                if (!map.ContainsKey(key))
                {
                    map[key] = new List <object>();
                }
                map[key].Add(model);
                objectCount++;
            }

            // Sort the items within each group
            // TODO: Give parameters a ModelComparer property
            OLVColumn           primarySortColumn = parmameters.SortItemsByPrimaryColumn ? parmameters.ListView.GetColumn(0) : parmameters.PrimarySort;
            ModelObjectComparer sorter            = new ModelObjectComparer(primarySortColumn, parmameters.PrimarySortOrder,
                                                                            parmameters.SecondarySort, parmameters.SecondarySortOrder);

            foreach (object key in map.Keys)
            {
                map[key].Sort(sorter);
            }

            // Make a list of the required groups
            List <OLVGroup> groups = new List <OLVGroup>();

            foreach (object key in map.Keys)
            {
                string title = parmameters.GroupByColumn.ConvertGroupKeyToTitle(key);
                if (!String.IsNullOrEmpty(parmameters.TitleFormat))
                {
                    int    count  = map[key].Count;
                    string format = (count == 1 ? parmameters.TitleSingularFormat : parmameters.TitleFormat);
                    try {
                        title = String.Format(format, title, count);
                    } catch (FormatException) {
                        title = "Invalid group format: " + format;
                    }
                }
                OLVGroup lvg = new OLVGroup(title);
                lvg.Collapsible      = folv.HasCollapsibleGroups;
                lvg.Key              = key;
                lvg.SortValue        = key as IComparable;
                lvg.Contents         = map[key].ConvertAll <int>(delegate(object x) { return(folv.IndexOf(x)); });
                lvg.VirtualItemCount = map[key].Count;
                if (parmameters.GroupByColumn.GroupFormatter != null)
                {
                    parmameters.GroupByColumn.GroupFormatter(lvg, parmameters);
                }
                groups.Add(lvg);
            }

            // Sort the groups
            if (parmameters.GroupByOrder != SortOrder.None)
            {
                groups.Sort(parmameters.GroupComparer ?? new OLVGroupComparer(parmameters.GroupByOrder));
            }

            // Build an array that remembers which group each item belongs to.
            this.indexToGroupMap = new List <int>(objectCount);
            this.indexToGroupMap.AddRange(new int[objectCount]);

            for (int i = 0; i < groups.Count; i++)
            {
                OLVGroup   group   = groups[i];
                List <int> members = (List <int>)group.Contents;
                foreach (int j in members)
                {
                    this.indexToGroupMap[j] = i;
                }
            }

            return(groups);
        }
예제 #11
0
 /// <summary>
 /// Return the index at which the given item is shown in the given group
 /// </summary>
 /// <param name="group"></param>
 /// <param name="itemIndex"></param>
 /// <returns></returns>
 public virtual int GetIndexWithinGroup(OLVGroup group, int itemIndex)
 {
     return(-1);
 }
예제 #12
0
 /// <summary>
 /// Return the index of the item that appears at the given position within the given group.
 /// </summary>
 /// <param name="group"></param>
 /// <param name="indexWithinGroup"></param>
 /// <returns></returns>
 public virtual int GetGroupMember(OLVGroup group, int indexWithinGroup)
 {
     return(-1);
 }
예제 #13
0
        /// <summary>
        /// Create a OlvListViewHitTestInfo
        /// </summary>
        public OlvListViewHitTestInfo(OLVListItem olvListItem, OLVListSubItem subItem, int flags, OLVGroup group) {
            this.item = olvListItem;
            this.subItem = subItem;
            this.location = ConvertNativeFlagsToDotNetLocation(olvListItem, flags);
            this.HitTestLocationEx = (HitTestLocationEx)flags;
            this.Group = group;

            switch (location) {
                case ListViewHitTestLocations.StateImage:
                    this.HitTestLocation = HitTestLocation.CheckBox;
                    break;
                case ListViewHitTestLocations.Image:
                    this.HitTestLocation = HitTestLocation.Image;
                    break;
                case ListViewHitTestLocations.Label:
                    this.HitTestLocation = HitTestLocation.Text;
                    break;
                default:
                    if ((this.HitTestLocationEx & HitTestLocationEx.LVHT_EX_GROUP_COLLAPSE) == HitTestLocationEx.LVHT_EX_GROUP_COLLAPSE)
                        this.HitTestLocation = HitTestLocation.GroupExpander;
                    else if ((this.HitTestLocationEx & HitTestLocationEx.LVHT_EX_GROUP_MINUS_FOOTER_AND_BKGRD) != 0)
                        this.HitTestLocation = HitTestLocation.Group;
                    else
                        this.HitTestLocation = HitTestLocation.Nothing;
                    break;
            }
        }
예제 #14
0
        /// <summary>
        /// Create a OlvListViewHitTestInfo
        /// </summary>
        public OlvListViewHitTestInfo(OLVListItem olvListItem, OLVListSubItem subItem, int flags, OLVGroup group, int iColumn)
        {
            this.item              = olvListItem;
            this.subItem           = subItem;
            this.location          = ConvertNativeFlagsToDotNetLocation(olvListItem, flags);
            this.HitTestLocationEx = (HitTestLocationEx)flags;
            this.Group             = group;
            this.ColumnIndex       = iColumn;
            this.ListView          = olvListItem == null ? null : (ObjectListView)olvListItem.ListView;

            switch (location)
            {
            case ListViewHitTestLocations.StateImage:
                this.HitTestLocation = HitTestLocation.CheckBox;
                break;

            case ListViewHitTestLocations.Image:
                this.HitTestLocation = HitTestLocation.Image;
                break;

            case ListViewHitTestLocations.Label:
                this.HitTestLocation = HitTestLocation.Text;
                break;

            default:
                if ((this.HitTestLocationEx & HitTestLocationEx.LVHT_EX_GROUP_COLLAPSE) == HitTestLocationEx.LVHT_EX_GROUP_COLLAPSE)
                {
                    this.HitTestLocation = HitTestLocation.GroupExpander;
                }
                else if ((this.HitTestLocationEx & HitTestLocationEx.LVHT_EX_GROUP_MINUS_FOOTER_AND_BKGRD) != 0)
                {
                    this.HitTestLocation = HitTestLocation.Group;
                }
                else
                {
                    this.HitTestLocation = HitTestLocation.Nothing;
                }
                break;
            }
        }
예제 #15
0
 /// <summary>
 /// Trigger a GroupExpandCollapse event and return true if the action was cancelled
 /// </summary>
 /// <param name="group"></param>
 /// <returns></returns>
 protected virtual bool TriggerGroupExpandCollapse(OLVGroup group)
 {
     GroupExpandingCollapsingEventArgs args = new GroupExpandingCollapsingEventArgs(group);
     this.OnGroupExpandingCollapsing(args);
     return args.Canceled;
 }
        public override IList <OLVGroup> GetGroups(GroupingParameters parms)
        {
            Converter <object, int> converter = null;
            FastObjectListView      folv      = (FastObjectListView)parms.ListView;
            int capacity = 0;
            NullableDictionary <object, List <object> > dictionary = new NullableDictionary <object, List <object> >();

            foreach (object obj2 in folv.Objects)
            {
                object groupKey = parms.GroupByColumn.GetGroupKey(obj2);
                if (!dictionary.ContainsKey(groupKey))
                {
                    dictionary[groupKey] = new List <object>();
                }
                dictionary[groupKey].Add(obj2);
                capacity++;
            }
            OLVColumn           col      = parms.SortItemsByPrimaryColumn ? parms.ListView.GetColumn(0) : parms.PrimarySort;
            ModelObjectComparer comparer = new ModelObjectComparer(col, parms.PrimarySortOrder, parms.SecondarySort, parms.SecondarySortOrder);

            foreach (object obj3 in dictionary.Keys)
            {
                dictionary[obj3].Sort(comparer);
            }
            List <OLVGroup> list = new List <OLVGroup>();

            foreach (object obj3 in dictionary.Keys)
            {
                string str = parms.GroupByColumn.ConvertGroupKeyToTitle(obj3);
                if (!string.IsNullOrEmpty(parms.TitleFormat))
                {
                    int count = dictionary[obj3].Count;
                    str = string.Format((count == 1) ? parms.TitleSingularFormat : parms.TitleFormat, str, count);
                }
                OLVGroup group = new OLVGroup(str)
                {
                    Key       = obj3,
                    SortValue = obj3 as IComparable
                };
                if (converter == null)
                {
                    converter = x => folv.IndexOf(x);
                }
                group.Contents         = dictionary[obj3].ConvertAll <int>(converter);
                group.VirtualItemCount = dictionary[obj3].Count;
                if (parms.GroupByColumn.GroupFormatter != null)
                {
                    parms.GroupByColumn.GroupFormatter(group, parms);
                }
                list.Add(group);
            }
            list.Sort(new OLVGroupComparer(parms.PrimarySortOrder));
            this.indexToGroupMap = new List <int>(capacity);
            this.indexToGroupMap.AddRange(new int[capacity]);
            for (int i = 0; i < list.Count; i++)
            {
                OLVGroup   group2   = list[i];
                List <int> contents = (List <int>)group2.Contents;
                foreach (int num4 in contents)
                {
                    this.indexToGroupMap[num4] = i;
                }
            }
            return(list);
        }
예제 #17
0
 public GroupTaskClickedEventArgs(OLVGroup group)
 {
     this.group = group;
 }
 public override int GetIndexWithinGroup(OLVGroup group, int itemIndex)
 {
     return(group.Contents.IndexOf(itemIndex));
 }
예제 #19
0
 /// <summary>
 /// Create a GroupExpandingCollapsingEventArgs
 /// </summary>
 /// <param name="group"> </param>
 public GroupExpandingCollapsingEventArgs(OLVGroup group) {
     if (group == null) throw new ArgumentNullException("group");
     this.olvGroup = group;
 }
예제 #20
0
 /// <summary>
 /// Return the index of the item that appears at the given position within the given group.
 /// </summary>
 /// <param name="group"></param>
 /// <param name="indexWithinGroup"></param>
 /// <returns></returns>
 public virtual int GetGroupMember(OLVGroup group, int indexWithinGroup) {
     return -1;
 }
예제 #21
0
        /// <summary>
        /// Make a list of groups that should be shown according to the given parameters
        /// </summary>
        /// <param name="parms"></param>
        /// <returns>The list of groups to be created</returns>
        /// <remarks>This should not change the state of the control. It is possible that the
        /// groups created will not be used. They may simply be discarded.</remarks>
        protected virtual IList<OLVGroup> MakeGroups(GroupingParameters parms)
        {
            // There is a lot of overlap between this method and FastListGroupingStrategy.MakeGroups()
            // Any changes made here may need to be reflected there

            // Separate the list view items into groups, using the group key as the descrimanent
            NullableDictionary<object, List<OLVListItem>> map = new NullableDictionary<object, List<OLVListItem>>();
            foreach (OLVListItem olvi in parms.ListView.Items) {
                object key = parms.GroupByColumn.GetGroupKey(olvi.RowObject);
                if (!map.ContainsKey(key))
                    map[key] = new List<OLVListItem>();
                map[key].Add(olvi);
            }

            // Sort the items within each group (unless specifically turned off)
            OLVColumn primarySortColumn = parms.SortItemsByPrimaryColumn ? parms.ListView.GetColumn(0) : parms.PrimarySort;
            if (primarySortColumn != null && parms.PrimarySortOrder != SortOrder.None) {
                ColumnComparer itemSorter = new ColumnComparer(primarySortColumn, parms.PrimarySortOrder,
                    parms.SecondarySort, parms.SecondarySortOrder);
                foreach (object key in map.Keys) {
                    map[key].Sort(parms.ItemComparer ?? itemSorter);
                }
            }

            // Make a list of the required groups
            List<OLVGroup> groups = new List<OLVGroup>();
            foreach (object key in map.Keys) {
                string title = parms.GroupByColumn.ConvertGroupKeyToTitle(key);
                if (!String.IsNullOrEmpty(parms.TitleFormat)) {
                    int count = map[key].Count;
                    string format = (count == 1 ? parms.TitleSingularFormat : parms.TitleFormat);
                    try {
                        title = String.Format(format, title, count);
                    } catch (FormatException) {
                        title = "Invalid group format: " + format;
                    }
                }

                OLVGroup lvg = new OLVGroup(title);
                lvg.Collapsible = this.HasCollapsibleGroups;
                lvg.Key = key;
                lvg.SortValue = key as IComparable;
                lvg.Items = map[key];
                if (parms.GroupByColumn.GroupFormatter != null)
                    parms.GroupByColumn.GroupFormatter(lvg, parms);
                groups.Add(lvg);
            }

            // Sort the groups
            if (parms.GroupByOrder != SortOrder.None)
                groups.Sort(parms.GroupComparer ?? new OLVGroupComparer(parms.GroupByOrder));

            return groups;
        }
예제 #22
0
        public override IList <OLVGroup> GetGroups(GroupingParameters parms)
        {
            // This strategy can only be used on FastObjectListViews
            FastObjectListView folv = (FastObjectListView)parms.ListView;

            // Separate the list view items into groups, using the group key as the descrimanent
            int objectCount = 0;
            NullableDictionary <object, List <object> > map = new NullableDictionary <object, List <object> >();

            foreach (object model in folv.Objects)
            {
                object key = parms.GroupByColumn.GetGroupKey(model);
                if (!map.ContainsKey(key))
                {
                    map[key] = new List <object>();
                }
                map[key].Add(model);
                objectCount++;
            }

            // Sort the items within each group
            OLVColumn           primarySortColumn = parms.SortItemsByPrimaryColumn ? parms.ListView.GetColumn(0) : parms.PrimarySort;
            ModelObjectComparer sorter            = new ModelObjectComparer(primarySortColumn, parms.PrimarySortOrder,
                                                                            parms.SecondarySort, parms.SecondarySortOrder);

            foreach (object key in map.Keys)
            {
                map[key].Sort(sorter);
            }

            // Make a list of the required groups
            List <OLVGroup> groups = new List <OLVGroup>();

            foreach (object key in map.Keys)
            {
                string title = parms.GroupByColumn.ConvertGroupKeyToTitle(key);
                if (!String.IsNullOrEmpty(parms.TitleFormat))
                {
                    int count = map[key].Count;
                    title = String.Format((count == 1 ? parms.TitleSingularFormat : parms.TitleFormat), title, count);
                }
                OLVGroup lvg = new OLVGroup(title);
                lvg.Key              = key;
                lvg.SortValue        = key as IComparable;
                lvg.Contents         = map[key].ConvertAll <int>(delegate(object x) { return(folv.IndexOf(x)); });
                lvg.VirtualItemCount = map[key].Count;
                if (parms.GroupByColumn.GroupFormatter != null)
                {
                    parms.GroupByColumn.GroupFormatter(lvg, parms);
                }
                groups.Add(lvg);
            }

            // Sort the groups
            groups.Sort(new OLVGroupComparer(parms.PrimarySortOrder));

            // Build an array that remembers which group each item belongs to.
            this.indexToGroupMap = new List <int>(objectCount);
            this.indexToGroupMap.AddRange(new int[objectCount]);

            for (int i = 0; i < groups.Count; i++)
            {
                OLVGroup   group   = groups[i];
                List <int> members = (List <int>)group.Contents;
                foreach (int j in members)
                {
                    this.indexToGroupMap[j] = i;
                }
            }

            return(groups);
        }