Exemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Create grouping for collection
            ObservableCollection <GroupInfoCollection <Item> > parts = new ObservableCollection <GroupInfoCollection <Item> >();

            //Implement grouping through LINQ queries
            var query = from item in _items
                        group item by item.Ref into g
                        select new { GroupName = g.Key, Items = g };

            //Populate Mountains grouped collection with results of the query
            foreach (var g in query)
            {
                GroupInfoCollection <Item> info = new GroupInfoCollection <Item>();
                info.Key = g.GroupName;
                foreach (var item in g.Items)
                {
                    info.Add(item);
                }
                parts.Add(info);
            }
            groupedItems = new CollectionViewSource();
            groupedItems.IsSourceGrouped = true;
            groupedItems.Source          = parts;
            DataGridView1.RowGroupHeaderPropertyNameAlternative = "Ref";
            DataGridView1.ItemsSource = groupedItems.View;
            Sort.IsEnabled            = false;
        }
        /// <summary>
        /// If the selection in the combo-box for the group-selection changes,
        /// the grouped grid view scrolls the selected group into view. This is
        /// especially useful in narrow views.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event arguments.
        /// </param>
        private void GroupComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string key = GroupComboBox.SelectedItem as string;
            GroupInfoCollection <Item> group = _source.Single(groupInfoList => groupInfoList.Key == key);

            ItemsByCategory.ScrollIntoView(group);
        }
        // Grouping implementation using LINQ
        public CollectionViewSource GroupData()
        {
            ObservableCollection <GroupInfoCollection <DataGridDataItem> > groups = new ObservableCollection <GroupInfoCollection <DataGridDataItem> >();
            var query = from item in _items
                        orderby item
                        group item by item.Range into g
                        select new { GroupName = g.Key, Items = g };

            foreach (var g in query)
            {
                GroupInfoCollection <DataGridDataItem> info = new GroupInfoCollection <DataGridDataItem>();
                info.Key = g.GroupName;
                foreach (var item in g.Items)
                {
                    info.Add(item);
                }

                groups.Add(info);
            }

            groupedItems = new CollectionViewSource();
            groupedItems.IsSourceGrouped = true;
            groupedItems.Source          = groups;

            return(groupedItems);
        }
Exemplo n.º 4
0
        public ListItems Convert(GroupInfoCollection groups)
        {
            var items = groups
                        .Select(group => Mapper.Map <ListItem>(group))
                        .ToArray();

            return(new ListItems(items, 1, 1));
        }
Exemplo n.º 5
0
        public ListItems Convert(GroupInfoCollection groups)
        {
            var items = groups
                .Select(group => new ListItem(group.GroupId, group.GroupName))
                .ToArray();

            return new ListItems(items, 1, 1);
        }
Exemplo n.º 6
0
        public ListItems Convert(GroupInfoCollection groups)
        {
            var items = groups
                .Select(group => Mapper.Map<ListItem>(group))
                .ToArray();

            return new ListItems(items, 1, 1);
        }
Exemplo n.º 7
0
        static public void ConvertOldGroupInfo(GroupInfo rootGroupInfo)
        {
            if (rootGroupInfo == null || rootGroupInfo.SubGroupInfo == null)
            {
                return;
            }

            GroupInfoCollection groupInfos = GetOldGroupInfo(rootGroupInfo);

            SetNewGroupInfo(rootGroupInfo, groupInfos);
        }
        /// <summary>
        /// If the data structure bound to the grid-view changes and causes the layout to update
        /// (i.e. if an item was added), it is scrolled to the category in the combo box.
        /// We can't call the scroll directly after adding the item (in AddItemClick), because
        /// we have to wait until the dependency property signals the control that it changed and
        /// the control changed its layout. If a new column is added by adding the new item, the control
        /// wouldn't scroll that new column into view otherwise.
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The event arguments</param>
        private void ItemsByCategoryLayoutUpdated(object sender, object e)
        {
            int needsToScroll = Interlocked.Exchange(ref _itemAdded, 0);

            if (needsToScroll != 0)
            {
                string key = GroupComboBox.SelectedItem as string;
                GroupInfoCollection <Item> group = _source.Single(groupInfoList => groupInfoList.Key == key);
                ItemsByCategory.ScrollIntoView(group);
            }
        }
Exemplo n.º 9
0
        public void PeopleGetPublicGroupsBasicTest()
        {
            GroupInfoCollection groups = Instance.PeopleGetPublicGroups(Data.UserId);

            Assert.AreNotEqual(0, groups.Count, "PublicGroupInfoCollection.Count should not be zero.");

            foreach (GroupInfo group in groups)
            {
                Assert.IsNotNull(group.GroupId, "GroupId should not be null.");
                Assert.IsNotNull(group.GroupName, "GroupName should not be null.");
            }
        }
Exemplo n.º 10
0
        static private void SetNewGroupInfo(GroupInfo rootGroupInfo, GroupInfoCollection groupInfos)
        {
            rootGroupInfo.SubGroupInfo = null;

            rootGroupInfo.SubGroupInfos.Clear();

            GroupInfo groupInfo = rootGroupInfo;

            foreach (GroupInfo subGroupInfo in groupInfos)
            {
                groupInfo.SubGroupInfos.Add(subGroupInfo);

                groupInfo = subGroupInfo;
            }
        }
Exemplo n.º 11
0
        static private GroupInfoCollection GetOldGroupInfo(GroupInfo rootGroupInfo)
        {
            GroupInfoCollection groupInfos = new GroupInfoCollection();

            GroupInfo groupInfo = rootGroupInfo;

            while (groupInfo.SubGroupInfo != null)
            {
                groupInfos.Add(groupInfo.SubGroupInfo.Copy());

                groupInfo = groupInfo.SubGroupInfo;
            }

            return(groupInfos);
        }
        /// <summary>
        /// The event handler for the click event of the AddItem button.
        /// The method creates a new object of type <see cref="Item"/>.
        /// From the observable collection containing the groups, the collection
        /// for the selected group is selected. The Single-query will always succeed,
        /// because the drop-down contains exactly the set of groups that is present
        /// in _source. Then the new item is added to the collection. As both
        /// collections are observable and are connected to the controls using data
        /// binding, the list will automatically update.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event arguments.
        /// </param>
        private void AddItemClick(object sender, RoutedEventArgs e)
        {
            string path = string.Format(
                CultureInfo.InvariantCulture,
                "SampleData/Images/60{0}.png",
                PictureComboBox.SelectedItem);

            Item item = new Item
            {
                Title    = TitleTextBox.Text,
                Category = (string)GroupComboBox.SelectedItem
            };

            item.SetImage(StoreData.BaseUri, path);

            GroupInfoCollection <Item> group =
                _source.Single(groupInfoList => groupInfoList.Key == item.Category);

            group.Add(item);
            Interlocked.Increment(ref _itemAdded);
        }